Skip to main content

Accelerated Kubernetes configuration and package management with Python.

Project description

PyPI version Documentation Status build status coverage report Code style: black Code style: flake8 Code style: mypy

Kuber

kuber is Python library for the management of Kubernetes resources. It's ideal for collectively managing groups of resources throughout their lifecycle. Resource definitions can be created and managed entirely in Python code (the pure-Python approach), but kuber is most effective when used in a hybrid fashion that combines configuration files and Python code. kuber also integrates and maintains compatibility with the lower-level official Kubernetes Python client, while abstracting basic CRUD operations into higher level constructs more inline with the behaviors of tools like kubectl and helm.

Key Functionality

Here are some key things that kuber does well:

  • A flexible workflow for managing Kubernetes resource configuration in Python code.
  • The ability to load resources directly from YAML or JSON configuration files, modify them in code and then use them or save them back to YAML/JSON files.
  • Resource bundling for managing groups of resource configurations collectively.
  • CRUD operations exposed directly on the resource objects to reduce the overhead in managing low-level clients.
  • Convenience functions that simplify common operations, e.g. managing containers within pods from the root resource.
  • Very thorough type-hinting and object structure to support creating accurate resource configurations and catch errors before runtime.
  • All resources and sub-resources support used in with blocks as context managers to simplify making multiple changes to a sub-resource.
  • Simultaneous support for multiple Kubernetes API versions. Manage multiple Kubernetes API versions (e.g. while promoting new versions from development to production) without having to pin and switch Python environments.

Installation

kuber available for installation with pip:

$ pip install kuber

Quickstart

kuber can be used to manage individual resources or a group of resources collectively. kuber is also very flexible about how resources are created - either directly from Python or by loading and parsing YAML/JSON configuration files. The first example shows the multi-resource management path:

import kuber
from kuber.latest import apps_v1

# Create a bundle and load all resource definitions from the
# `app_configs` directory as well as the `app-secret.yaml`
# configuration file from the local `secrets` directory.
resource_bundle = (
    kuber.create_bundle()
    .add_directory("app_configs")
    .add_file("secrets/app-secret.yaml")
)

# Modify the metadata labels on all resources in the bundle.
for resource in resource_bundle.resources:
    resource.metadata.labels.update(environment="production")

# Update the replica count of the loaded deployment named
# "my-app" to the desired initial count.
d: apps_v1.Deployment = resource_bundle.get(
    name="my-app",
    kind="Deployment"
)
d.spec.replicas = 20

# Load the current `kubeconfig` cluster configuration into
# kuber for interaction with the cluster.
kuber.load_access_config()

# Turn this bundle script into a file that can be called from
# the command line to carry out CRUD operations on all the
# resources contained within it collectively. For example,
# to create the resources in this bundle, call this script
# file with a create argument.
resource_bundle.cli()

Or managing resources individually:

from kuber.latest import batch_v1

job = batch_v1.Job()

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

# Add a container to the job spec.
job.spec.append_container(
    name="main",
    image="my-registry.com/projects/my-job:1.0.1",
    image_pull_policy="Always",
    env=[batch_v1.EnvVar("ENVIRONMENT", "production")]
)

# Print the resulting YAML configuration for display. This
# could also be saved somewhere to use later as the
# configuration file to deploy to the cluster in cases
# like a multi-stage CI pipeline.
print(job.to_yaml())

Check out the kuber documentation for more details and examples.

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.18.0.tar.gz (3.6 MB view details)

Uploaded Source

Built Distribution

kuber-1.18.0-py3-none-any.whl (4.0 MB view details)

Uploaded Python 3

File details

Details for the file kuber-1.18.0.tar.gz.

File metadata

  • Download URL: kuber-1.18.0.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Windows/11

File hashes

Hashes for kuber-1.18.0.tar.gz
Algorithm Hash digest
SHA256 33398e1013f0099ce63e33fc6266ff50310df0bb4eaa9a8380ed7da5d88ced0c
MD5 238b74b8c27ace7c3dce2497c93002e5
BLAKE2b-256 a099f52dd1567871302873a2b445988cabfbc9fbaf0bd5d2915d8590a0089769

See more details on using hashes here.

File details

Details for the file kuber-1.18.0-py3-none-any.whl.

File metadata

  • Download URL: kuber-1.18.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Windows/11

File hashes

Hashes for kuber-1.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0adbc6b25862ea12a9cb180324ef6125731618a4359c964bd137f936567fc506
MD5 33fac73cb6d35bcb9fc01210e1158467
BLAKE2b-256 fdbd6d766cc024d9e33ea3b59cc41cdaf6f5fa869ce1e9692e6ff4628f93e709

See more details on using hashes here.

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