High-level Kubernetes resource configuration library.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for kuber-1.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c339174c1910e733d25e73ee44ab1dfb1ccb247faf3a1ef80996ab33b6bbf9 |
|
MD5 | 3019bbdf616365c3499f6fca0b1352b7 |
|
BLAKE2b-256 | 659cf0d6621fd5e4535ee7bda97f23708bd64972c6e1612168cff47dc65e7301 |