Skip to main content

High-level Kubernetes resource configuration API.

Project description

# Kuber

A high-level Python client for Kubernetes.

## tl;dr

import kuber
from kuber.v1_13.apps import v1 as apps_v1

# Create a bundle object to load and manage resource configurations
resource_bundle = (

# Modify the metadata labels on all resources in the bundle
for resource in resource_bundle.resources:

# Update the replica count of the loaded deployment for production
dep: apps_v1.Deployment = resource_bundle.get(name='my-app', kind='Deployment')
dep.spec.replicas = 20

# Print the combined YAML configuration for the bundle of resources

# Create all resources in the bundle

Or managing resources individually:

from kuber.v1_13.batch import v1 as batch_v1

job = batch_v1.Job()

# Populate metadata using context manager syntax for brevity
with job.metadata as md: = 'my-job'
md.namespace = 'jobs'
md.labels.update(component='backend-tasks', environment='production')

# Add a container to the job spec
env=[batch_v1.EnvVar('ENVIRONMENT', 'production')]

# Print the resulting YAML configuration for display

# Create the resource in the currently configured cluster

kuber supports the basic CRUD behaviors using the locally installed and
configured _kubectl_ as the intermediary. For more advanced and custom
operations, the resource configurations can always be serialized to YAML
or JSON and used in custom defined commands or just saved to disk for later
application. The resource configurations also have a `to_dict()` function
that serializes down to a Python dictionary that is compatible with the
low-level _kubernetes_ library client APIs (passed into the _body_ parameter).

## Background

The [Official Python Kubernetes client](
exists to provide low-level access to the Kubernetes API. However, low-level
access can be clunky to use and require an additional barrier to entry for those
of us that are not Kubernetes API experts. Generally, the lower-level API
functionality is abstracted away from us with tools like _kubectl_.

_kuber_ is a higher-level abstraction designed to be compliant with the general
usage level of someone comfortable working with Kubernetes configuration files
and managing them with tools like _kubectl_ (and _helm_). _kuber_ was created
because we found that managing complex configurations through configuration
files alone was causing friction and that introducing tools like _helm_ that
rely on templating wasn't fully solving the problem.

## Configuring Resources

_kuber_ allows Kubernetes resources to be defined entirely in Python code,
or defined in configuration files and loaded and modified by code. Examples of
the two approaches are shown below:

### The Pure Python Approach

Here's an example of how a Deployment can be created with _kuber_:

from kuber.v1_13.apps import v1 as apps_v1

# Create a deployment using Kubernetes version 1.13
# from the apps/v1 API version.
d = apps_v1.Deployment()

with d.metadata as md: = 'my-deployment'
md.namespace = 'my-app'
md.labels.update(app='foo', component='application')


ports=[apps_v1.ContainerPort(container_port=8080, host_port=80)],
limits={'cpu': '1.5', 'memory': '1Gi'},
requests={'cpu': '1.5', 'memory': '800Mi'},

# Render the results to YAML

The printed output of executing this would be:

apiVersion: apps/v1
kind: Deployment
app: foo
component: application
name: my-deployment
namespace: my-app
- image: my-app:1.0
imagePullPolicy: Always
name: app
- containerPort: 8080
hostPort: 80
cpu: '1'
memory: 1Gi
cpu: '1'
memory: 800Mi
tty: true

### The Hybrid Approach

In many cases it is convenient to use standard Kubernetes configuration as a
base template. The common approach in these cases used by projects like
[Helm]( is to introduce a templating language into the
configuration files that gets rendered prior to using the configuration.
However, this approach has a number of drawbacks. Instead _Kuber_ facilitates
flexible modification and augmentation of resource configurations that have
been loaded from configuration files.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kuber-1.0.0.tar.gz (1.1 MB view hashes)

Uploaded Source

Built Distribution

kuber-1.0.0-py2.py3-none-any.whl (1.3 MB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page