Skip to main content

Kubernetes Lite is a "liteweight" wrapper around various golang Kubernetes libraries using gopy

Project description

Kubernetes Lite

Kubernetes Lite is a "liteweight" wrapper around various golang Kubernetes libraries using gopy. It brings the benefits of go's resource efficiency plus the feature set of packages like client-go and the controller-runtime to Python.

Documentation

Get going with our examples page or jump into more details with our API Reference!

Installation

[!WARNING] Since go 1.21 having multiple go shared objects in the same process is not supported. Thus you can not use other CGO based libraries with kubernetes-lite. If you would like to combine this package with another golang based one then please open an issue so we can discuss possible solutions.

Kubernetes Lite provides precompiled both x86 and arm wheels for Linux and MacOS. You can install the package with the standard pip install

pip3 install kubernetes_lite

Source Installation

To install Kubernetes Lite from source, you must install golang 1.23. You should then let setup-tools/pip install the package like normal.

pip3 install --no-binary "kubernetes_lite" kubernetes_lite

Dynamic Client

Kubernetes Lite exposes client-go's dynamic client, which, on average, is 20% faster and uses half the memory than the standard Kubernetes library. It supports all of the options defined by apimachinery in both their JSON and camelCase formats. See the examples folder for a recreation of client-go's own dynamic example.

In addition to the usage example you can check out the Api Reference for a detailed description of all methods and options.

from kubernetes_lite.client import DynamicClient

# Construct a client using https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client/config#GetConfig
client = DynamicClient()
# List all deployments in a cluster
client.resource("apps/v1","Deployment").list()

The following graphs highlight the speed and efficiency of the dynamic client. One caveat is that the "20%" runtime improvement is on top of a fast standard client. The official client is only 1-3ms behind Kubernetes Lite, which would not impact a networked client where network latencies usually are much higher than 1ms. The real benefit of Kubernetes Lite's resource efficiency is startup time. If you have a simple script that needs to be run at frequent intervals, the startup save of 300ms can be impactful.

client runtime operation timings client startup operation timings client memory usage

EnvTest

To aid in testing all Python Kubernetes libraries, Kubernetes Lite also provides bindings to the controller-runtime's envtest package. This allows you to start a local control plane without needing a container runtime, which provides users real API server to test against, replacing the need for complicated "mock" clients and servers. As shown in our examples folder, these bindings and pytest fixtures work with any Kubernetes client, including the official one.

# Import standard Kubernetes client
from kubernetes import client, config
# Import Kubernetes Lite Fixture
from kubernetes_lite.envtest.pytest import session_kubernetes_env, EnvTest

def test_kubernetes_core_api(session_kubernetes_env: EnvTest):
    """Test that kubernetes core api works with envtest"""
    config.load_config(config_file=session_kubernetes_env.config())

    v1 = client.CoreV1Api()
    print("Listing pods with their IPs:")
    ret = v1.list_pod_for_all_namespaces(watch=False)
    for i in ret.items:
        print(f"{i.status.pod_ip}\t{i.metadata.namespace}\t{i.metadata.name}")

The EnvTest class was designed to be compatible with the controller-runtime version. It uses the same environmental configuration as go with support for envvars like KUBEBUILDER_ASSETS and USE_EXISTING_CLUSTER. For a complete guide to envtest checkout the controller-runtimes Configuring Envtest guide. The code snippets will be different; instead of setup-envtest, it will be python3 -m kubernetes_lite.setup_envtest, but the guide is still applicable.

Setup EnvTest

Along with envtest, Kubernetes Lite wraps it's helper script setup-envtest. This script is automatically called when starting an EnvTest instance but it can also be invoked manually with python3 -m kubernetes_lite.setup_envtest. It has the exact same options and use as the go version.

 python3 -m kubernetes_lite.setup_envtest use
Version: 1.32.0
OS/Arch: darwin/amd64
sha512: a7824ff8ae9c5062bcbde243a7a3a1c76e02de0c92e2b332daf1954405aeded856023f277d74197862d0d5909e9e1dca451b5f2e84796e451ad6011ec98f8433
Path: /Users/michaelhonaker/Library/Application Support/io.kubebuilder.envtest/k8s/1.32.0-darwin-amd64

Contributing

Check out our contributing guide to learn how to contribute to Kubernetes Lite.

Code of Conduct

Participation in Kubernetes Lite is governed by our Code of Conduct.

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

kubernetes_lite-0.0.4.tar.gz (360.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kubernetes_lite-0.0.4-cp311-abi3-musllinux_1_2_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

kubernetes_lite-0.0.4-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

kubernetes_lite-0.0.4-cp311-abi3-macosx_11_0_arm64.whl (11.6 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

kubernetes_lite-0.0.4-cp311-abi3-macosx_10_9_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.11+macOS 10.9+ x86-64

File details

Details for the file kubernetes_lite-0.0.4.tar.gz.

File metadata

  • Download URL: kubernetes_lite-0.0.4.tar.gz
  • Upload date:
  • Size: 360.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kubernetes_lite-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4ddced799a9537b991712aa11142e4f883364b5f0237c85d62aad211e2fcd5ed
MD5 d721e641df96e27ef8dd27395d414a8c
BLAKE2b-256 f5c6a371a597f294d22cfeca40a0e525ab75ba21fd41aebe452e815e2dceaebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.4.tar.gz:

Publisher: publish_release.yml on IBM/Kubernetes-Lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kubernetes_lite-0.0.4-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.4-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7dab51d60815c2d746d9fecaed4e52d0058bfe4d59ac21dbc2cf699b43c2cd4
MD5 55b0604f94333eecdc50574530135857
BLAKE2b-256 fb919a1004e55fca09040da00b1f9a6a617e4ec4e627a65ee68cdd0f26bf1d92

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.4-cp311-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish_release.yml on IBM/Kubernetes-Lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kubernetes_lite-0.0.4-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.4-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47695ab6b2e7998fa160418815f3631f1c3dcc1731c326bfba50b8714479e7a2
MD5 3ba57a20a77f38dff9c3d93da3e66c7e
BLAKE2b-256 2b4acff6c59a3e7f465be9070675b82fcccf5c3fada11d7007c950ec7da355dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.4-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish_release.yml on IBM/Kubernetes-Lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kubernetes_lite-0.0.4-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.4-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ecb52b5883631a4c48bc573f8139be7b868105dfc356b0ae89416e110f96bdc
MD5 d6d14d8ef80676ac6c2ac94bf9b95716
BLAKE2b-256 57751bd08c8b3365ca2b8f13d597d60e257a96721ebf80545ef13ebaccb2005e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.4-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: publish_release.yml on IBM/Kubernetes-Lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kubernetes_lite-0.0.4-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.4-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cf974b26977354d8a8fc81be03407cb3fb182c560df2b4df5249c9fbb9927de7
MD5 554c641ae8ea9dd00b39282847e49c6e
BLAKE2b-256 16a01117a98ecd334fec1c2eef481b34c3ce77d5e41bc4d466c4bea817698703

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.4-cp311-abi3-macosx_10_9_x86_64.whl:

Publisher: publish_release.yml on IBM/Kubernetes-Lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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