A Kubernetes API library
Project description
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
andtrio
. - 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.12.4.tar.gz
(2.8 MB
view details)
Built Distribution
kr8s-0.12.4-py3-none-any.whl
(50.1 kB
view details)
File details
Details for the file kr8s-0.12.4.tar.gz
.
File metadata
- Download URL: kr8s-0.12.4.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2271e1d16a6c4d84043961ad8af4c0bea2c8a4b51cb9c67c667f578404ccd94 |
|
MD5 | d0db252a5617ead58332932d60c21771 |
|
BLAKE2b-256 | 2350638754fe8e5eeb907a8e97679deed5c0ecbac6a3d074754c1510e24d2baa |
Provenance
File details
Details for the file kr8s-0.12.4-py3-none-any.whl
.
File metadata
- Download URL: kr8s-0.12.4-py3-none-any.whl
- Upload date:
- Size: 50.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40d3062af8081041b85e9bd00741f15f9ab0e7af7d63a2ae58b3c40305cb18d |
|
MD5 | 56120ae8613bc8fdfb066920fe4c5d5e |
|
BLAKE2b-256 | 87d8936a3cf57f609190a5e7706ed9a82a9c7ef66a5646f51a684e18a332d690 |