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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

kubernetes_lite-0.0.5-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.5-cp311-abi3-musllinux_1_2_aarch64.whl (11.8 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

kubernetes_lite-0.0.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (11.8 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

kubernetes_lite-0.0.5-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.5-cp311-abi3-macosx_11_0_arm64.whl (11.6 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

kubernetes_lite-0.0.5-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.5-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.5-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c3e9c4ed2f4cc193aee50c978f890fc5ccb81f5d356684e4a56882c80e710738
MD5 c5f5bd4700ac4c5ba8b0bf00850a5193
BLAKE2b-256 a6c09e580eb514bdf1be6cab1b2e1fb4631bdf50907ccf6d5cd182dde424307c

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.5-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.5-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.5-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5cd2f7c431bae800b7995132eaf81479e7fddd9432aec6813725c0d806d15a62
MD5 64f82d34475d74be5b942261ecdafa51
BLAKE2b-256 3e87da3b53662aa2876aa68b95834d1bc46c9b22e8f3059b8e09c2292e2b1607

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.5-cp311-abi3-musllinux_1_2_aarch64.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.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a9186d161d0d862ef626a389a908f1302abb3a806329b02e4f7ce1a20e9cbcac
MD5 e11e3e20fb440b795a2656be660f6710
BLAKE2b-256 44880c675f164a8b61c37c77f2e0647c55cb1196f81e2a4c87df7da182d0db8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.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.5-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.5-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30852a44de7cfce28f72a6ab0d3322f76298c445794eb178fe4cfce592d92a36
MD5 8395ebff14793e160bd52c2c220d6802
BLAKE2b-256 1ba50081f3f474861df7cca506cb46ff65b097773833ee527ca37db2a4be6da9

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.5-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.5-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.5-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1bc639f92d7298f03b4a0e8e3174a471a18893dbc78492f14dd80de55eaec1d3
MD5 121660e1ddac1fa7bcb0d405c973ef84
BLAKE2b-256 daddc5926bb81f6ef9aa6952b0d9504e8b04cf2e2b98978d3cb1564484e5084e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.5-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.5-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.5-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6fcdc933dcfc1a22118764c4214c5e7234115660fb8a8ed99beeb8cf42bb6e5
MD5 492cdcf243b29afdf6e4bcccc47d9079
BLAKE2b-256 5190ed86bb7987e45679c2bd564f69ee8921fa8ec3db887bb788964bf157b0ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.5-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