Skip to main content

High-level Kubernetes resource configuration library.

Project description

Documentation Status

What is kuber?

kuber is higher-level Python client for Kubernetes resource management that integrates and maintains compatibility with the lower-level official Kubernetes Python client. Additionally, kuber supports managing groups of resources collectively as a single entity directly in code.

Main Features

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.
import typing

import kuber
from kuber.latest import apps_v1

# Create a bundle object to load and manage resource configurations
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 for production. Use
# type casting here to make type-hinting and checking more explicit when
# making changes to the deployment resource.
d = typing.cast(
    apps_v1.Deployment, 
    resource_bundle.get(name='my-app', kind='Deployment')
)
d.spec.replicas = 20

# Print the combined YAML configuration for the bundle of resources
print(resource_bundle.render_yaml_bundle())

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
print(job.to_yaml())

Check out the kuber documentation for more detailed documentation.

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.2.4.tar.gz (2.0 MB view hashes)

Uploaded Source

Built Distribution

kuber-1.2.4-py2.py3-none-any.whl (4.1 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