Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
A simple, extensible Python client library for Kubernetes that feels familiar for folks who already know how to use kubectl
.
kubectl
for a shallow learning curve.asyncio
and trio
.kubectl
.$ pip install kr8s
[!TIP] See the Examples Documentation for a full set of examples including
asyncio
examples.
Print out all of the node names in the cluster.
import kr8s
for node in kr8s.get("nodes"):
print(node.name)
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 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)
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 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 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 to mark it as unschedulable.
from kr8s.objects import Node
node = Node("k8s-node-1")
node.cordon()
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
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.
FAQs
A Kubernetes API library
We found that kr8s demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.