Skip to main content

A Kubernetes API library

Project description

Test Codecov pre-commit.ci status Read the Docs PyPI PyPI - Python Version Kubernetes Version Support PyPI - Wheel PyPI - License

A simple, extensible Python client library for Kubernetes that feels familiar for folks who already know how to use kubectl.

Highlights

  • API inspired by kubectl to reduce developer learning curve.
  • Sensible defaults to reduce boiler plate.
  • No swagger generated code, human readable code only.
  • Also has an asynchronous API that can be used with asyncio and trio.
  • Client caching to reduce passing API objects around.
  • Batteries included by providing useful utilities and methods inspired by kubectl.

Quickstart

Installation

$ pip install kr8s

Examples

See the Examples Documentation for a full set of examples including asyncio examples.

List Nodes

Print out all of the node names in the cluster.

import kr8s

for node in kr8s.get("nodes"):
    print(node.name)

Create a Pod

Create a new Pod.

from kr8s.objects import Pod

pod = Pod({
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "name": "my-pod",
        },
        "spec": {
            "containers": [{"name": "pause", "image": "gcr.io/google_containers/pause",}]
        },
    })

pod.create()

Scale a Deployment

Scale the Deployment metrics-server in the Namespace kube-system to 1 replica.

from kr8s.objects import Deployment

deploy = Deployment.get("metrics-server", namespace="kube-system")
deploy.scale(1)

List Pods by label selector

Get all Pods from all Namespaces matching a label selector.

import kr8s

selector = {'component': 'kube-scheduler'}

for pod in kr8s.get("pods", namespace=kr8s.ALL, label_selector=selector):
    print(pod.namespace, pod.name)

Add a label to a Pod

Add the label foo with the value bar to an existing Pod.

from kr8s.objects import Pod

pod = Pod("kube-apiserver", namespace="kube-system")
pod.label({"foo": "bar"})

Cordon a Node

Cordon a Node to mark it as unschedulable.

from kr8s.objects import Node

node = Node("k8s-node-1")

node.cordon()
# Is equivalent to
# node.patch({"spec": {"unschedulable": True}})

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

kr8s-0.9.1.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

kr8s-0.9.1-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file kr8s-0.9.1.tar.gz.

File metadata

  • Download URL: kr8s-0.9.1.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for kr8s-0.9.1.tar.gz
Algorithm Hash digest
SHA256 7f21470ad4ae3ccc19aaea0cfb8c9d4df8825c3d52f74120f6515ecea29b1cbf
MD5 298eb53b09499203e01b34dbdb36fbf3
BLAKE2b-256 6dc4da598e484ee1d3f5408bf01f4b5cc03d0843cbc6dfe491b556565b1e1855

See more details on using hashes here.

Provenance

File details

Details for the file kr8s-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: kr8s-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for kr8s-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37619a52b181753e8276ba19c64c0d7131716dbd932b2e1be2349f205f8c071e
MD5 d91cc3732059dcd4c7e587a9b344b46f
BLAKE2b-256 1fe70e7320f279c2198edd152e2e64c5c1b45d8ade81bc1f5509e17b7e22dbf0

See more details on using hashes here.

Provenance

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