kr8s 0.20.15


pip install kr8s

  Latest version

Released: Jan 16, 2026


Meta
Author: Jacob Tomlimson
Requires Python: >=3.9

Classifiers

Programming Language
  • Python :: 3

Test Codecov pre-commit.ci status Read the Docs EffVer Versioning PyPI Python Version Support 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 for a shallow learning curve.
  • Sensible defaults to reduce boiler plate.
  • No swagger generated code, human readable code only.
  • Has both a standard and an async 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

[!TIP] 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"})

Generate a Pod

Generate a simple Pod with a couple of keyword arguments.

from kr8s.objects import Pod

pod = Pod.gen(name="example-1", image="nginx:latest")
pod.create()

Cordon a Node

Cordon a Node to mark it as unschedulable.

from kr8s.objects import Node

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

node.cordon()

Pod Exec

Exec a command in a Pod.

from kr8s.objects import Pod

pod = Pod.get("my-pod")

command = pod.exec(["uptime"])
print(command.stdout.decode())
# 13:49:05 up 23:03,  0 users,  load average: 0.66, 0.87, 0.85

Port forward a Pod

Open a port forward to a Pod as a background task/thread.

from kr8s.objects import Pod

pod = Pod.get("my-pod")
pf = pod.portforward(remote_port=1234, local_port=5678)

# Starts the port forward in a background thread
pf.start()

# Your other code goes here

# Optionally stop the port forward thread (it will exit with Python anyway)
pf.stop()

[!TIP] See the Examples Documentation for a full set of examples including asyncio examples.

0.20.15 Jan 16, 2026
0.20.14 Dec 01, 2025
0.20.13 Oct 28, 2025
0.20.12 Oct 24, 2025
0.20.11 Oct 22, 2025
0.20.10 Sep 23, 2025
0.20.9 Jul 08, 2025
0.20.8 Jun 26, 2025
0.20.7 Apr 28, 2025
0.20.6 Mar 03, 2025
0.20.5 Feb 27, 2025
0.20.4 Feb 13, 2025
0.20.3 Jan 27, 2025
0.20.2 Jan 27, 2025
0.20.1 Jan 22, 2025
0.20.0 Jan 20, 2025
0.19.1 Jan 07, 2025
0.19.0 Jan 06, 2025
0.18.1 Nov 12, 2024
0.18.0 Nov 03, 2024
0.17.4 Sep 18, 2024
0.17.3 Sep 10, 2024
0.17.2 Aug 01, 2024
0.17.1 Aug 01, 2024
0.17.0 Jul 04, 2024
0.16.2 Jul 01, 2024
0.16.1 Jun 13, 2024
0.16.0 Jun 11, 2024
0.15.0 Jun 04, 2024
0.14.6 Jun 03, 2024
0.14.5 May 22, 2024
0.14.4 Apr 30, 2024
0.14.3 Apr 24, 2024
0.14.2 Apr 19, 2024
0.14.1 Mar 19, 2024
0.14.0 Mar 13, 2024
0.13.6 Mar 07, 2024
0.13.5 Feb 29, 2024
0.13.4 Feb 29, 2024
0.13.3 Feb 13, 2024
0.13.2 Feb 08, 2024
0.13.1 Feb 02, 2024
0.13.0 Jan 22, 2024
0.12.15 Jan 09, 2024
0.12.14 Jan 09, 2024
0.12.13 Jan 09, 2024
0.12.12 Jan 09, 2024
0.12.11 Jan 03, 2024
0.12.10 Dec 18, 2023
0.12.9 Dec 15, 2023
0.12.8 Dec 13, 2023
0.12.7 Dec 13, 2023
0.12.6 Dec 12, 2023
0.12.5 Dec 11, 2023
0.12.4 Dec 05, 2023
0.12.3 Dec 04, 2023
0.12.2 Dec 04, 2023
0.12.1 Nov 28, 2023
0.12.0 Nov 28, 2023
0.11.0 Nov 21, 2023
0.10.0 Nov 06, 2023
0.9.2 Oct 17, 2023
0.9.1 Oct 17, 2023
0.9.0 Oct 12, 2023
0.8.20 Oct 09, 2023
0.8.19 Oct 04, 2023
0.8.18 Sep 14, 2023
0.8.17 Sep 07, 2023
0.8.16 Sep 05, 2023
0.8.15 Aug 24, 2023
0.8.13 Aug 24, 2023
0.8.12 Aug 08, 2023
0.8.11 Aug 04, 2023
0.8.10 Aug 01, 2023
0.8.9 Jul 31, 2023
0.8.8 Jul 31, 2023
0.8.7 Jul 27, 2023
0.8.6 Jul 13, 2023
0.8.5 Jul 13, 2023
0.8.4 Jul 11, 2023
0.8.3 Jul 07, 2023
0.8.2 Jul 07, 2023
0.8.1 Jul 06, 2023
0.8.0 Jul 05, 2023
0.7.0 Jul 03, 2023
0.6.0 Jun 29, 2023
0.5.2 Jun 11, 2023
0.5.1 Jun 11, 2023
0.5.0 Jun 10, 2023
0.4.1 May 24, 2023
0.4.0 May 10, 2023
0.3.0 May 05, 2023
0.2.0 Apr 06, 2023
0.1.0 Apr 06, 2023
0.1.0a0 Mar 23, 2023

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
anyio (>=3.7.0)
cachetools (>=5.2.0)
cryptography (>=35)
exceptiongroup (>=1.2.0)
httpx-ws (>=0.7.0)
httpx (>=0.24.1)
packaging (>=23.0)
python-box (>=7.0.1)
python-jsonpath (>=0.7.1)
pyyaml (>=6.0)
typing-extensions (>=4.12.2)