Skip to main content

No project description provided

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.

Examples

For examples using the library, please continue reading down below or check our examples folder.

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

Documentation

Get going with our Examples or jump into more details with the Python API docs.

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.3.tar.gz (351.5 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.3-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.3-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.3-cp311-abi3-macosx_11_0_arm64.whl (11.6 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

kubernetes_lite-0.0.3-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.3.tar.gz.

File metadata

  • Download URL: kubernetes_lite-0.0.3.tar.gz
  • Upload date:
  • Size: 351.5 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.3.tar.gz
Algorithm Hash digest
SHA256 457ffdd883caaf7c9df923317c35ae50a2d669a1290dc38f4ab12b83fc7e3be2
MD5 8d35576a5b88c116ecff631052371fce
BLAKE2b-256 8aa4ab0781b6077a343dab4612b04452f68ff762241f2feeac230765a94a533f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.3.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.3-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kubernetes_lite-0.0.3-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0f9296f45a3dd5673e16e28dfa3b2aee2fc48b905e8f10d188cfd58d82eac85c
MD5 66cc90d26578302c03aeebee98a72fb7
BLAKE2b-256 65ba66fb7a4c34678db80d214739b441bf4ddcd9e2725509f7a51c69262abd58

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_lite-0.0.3-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.3-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.3-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a2a8825d80609b926d22d4a225479be3645ed19b75b6de082dac0409ada9f2a
MD5 92278833d9c29eb59895dec129bdfafc
BLAKE2b-256 6cc33b3d47ebea2a7835cbba33ce4d955428a8f1cad97338cf54df12cdf92b3e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kubernetes_lite-0.0.3-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6f2d162baae26318acb84c4dd684349916fdd3dbf78d8be311ae3bb7c1cea8f
MD5 cdcd329f7b258ebc2e920bb3e5897907
BLAKE2b-256 11388cedaea3580ac9d93f5aa44f5ab4d8915f990c7254671c246a94dc5693ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kubernetes_lite-0.0.3-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 37c7360f7346cdb1075e6b4a1bd4612b52c7bd3733fb0bf17ce2718db6cf8d19
MD5 eec5aff078593278806f6f72272d43e7
BLAKE2b-256 93b275f6f8a5ccb9e46a051344152d70d9bb76f5184ae155b76f7e88e376e7d9

See more details on using hashes here.

Provenance

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