Modifying Resources

Scale a Deployment

Scale the Depoyment metrics-server using Deployment.scale() in the Namespace kube-system to 1 replica.

from kr8s.objects import Deployment

deploy = Deployment.get("metrics-server", namespace="kube-system")
deploy.scale(1)
from kr8s.asyncio.objects import Deployment

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

Add Pod label

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

from kr8s.objects import Pod

pod = Pod("kube-apiserver", namespace="kube-system")
pod.label({"foo": "bar"})
from kr8s.asyncio.objects import Pod

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

Replace all Pod labels

Using the JSON 6902 style patching replace all Pod labels with {"patched": "true"} using Pod.patch().

from kr8s.objects import Pod

pod = Pod("my-pod", namespace="kube-system")
pod.patch(
    [{"op": "replace", "path": "/metadata/labels", "value": {"patched": "true"}}],
    type="json",
)
from kr8s.asyncio.objects import Pod

pod = await Pod("my-pod", namespace="kube-system")
await pod.patch(
    [{"op": "replace", "path": "/metadata/labels", "value": {"patched": "true"}}],
    type="json",
)

Cordon a Node

Cordon a Node to mark it as unschedulable with Node.cordon().

from kr8s.objects import Node

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

node.cordon()
from kr8s.asyncio.objects import Node

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

await node.cordon()