kr8s.asyncio.objects

Objects to represent Kubernetes resources.

This module provides classes that represent Kubernetes resources. These classes are used to interact with resources in the Kubernetes API server.

Classes

APIObject

Base class for Kubernetes objects.

Binding

A Kubernetes Binding.

ClusterRole

A Kubernetes ClusterRole.

ClusterRoleBinding

A Kubernetes ClusterRoleBinding.

ComponentStatus

A Kubernetes ComponentStatus.

ConfigMap

A Kubernetes ConfigMap.

ControllerRevision

A Kubernetes ControllerRevision.

CronJob

A Kubernetes CronJob.

CustomResourceDefinition

A Kubernetes CustomResourceDefinition.

DaemonSet

A Kubernetes DaemonSet.

Deployment

A Kubernetes Deployment.

Endpoints

A Kubernetes Endpoints.

Event

A Kubernetes Event.

HorizontalPodAutoscaler

A Kubernetes HorizontalPodAutoscaler.

Ingress

A Kubernetes Ingress.

IngressClass

A Kubernetes IngressClass.

IPAddress

A Kubernetes IPAddress.

Job

A Kubernetes Job.

LimitRange

A Kubernetes LimitRange.

Namespace

A Kubernetes Namespace.

NetworkPolicy

A Kubernetes NetworkPolicy.

Node

A Kubernetes Node.

PersistentVolume

A Kubernetes PersistentVolume.

PersistentVolumeClaim

A Kubernetes PersistentVolumeClaim.

Pod

A Kubernetes Pod.

PodDisruptionBudget

A Kubernetes PodDisruptionBudget.

PodTemplate

A Kubernetes PodTemplate.

ReplicaSet

A Kubernetes ReplicaSet.

ReplicationController

A Kubernetes ReplicationController.

ResourceQuota

A Kubernetes ResourceQuota.

Role

A Kubernetes Role.

RoleBinding

A Kubernetes RoleBinding.

Secret

A Kubernetes Secret.

Service

A Kubernetes Service.

ServiceAccount

A Kubernetes ServiceAccount.

ServiceCIDR

A Kubernetes ServiceCIDR.

StatefulSet

A Kubernetes StatefulSet.

Table

A Kubernetes Table.

Functions

get_class(→ type[APIObject])

Get an APIObject subclass by kind and version.

new_class(→ type[APIObject])

Create a new APIObject subclass.

object_from_name_type(→ APIObject)

Create an APIObject from a Kubernetes resource name.

object_from_spec(→ APIObject)

Create an APIObject from a Kubernetes resource spec.

objects_from_files(→ list[APIObject])

Create APIObjects from Kubernetes resource files.

Module Contents

class kr8s.asyncio.objects.APIObject(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Base class for Kubernetes objects.

version: str
endpoint: str
kind: str
plural: str
singular: str
namespaced: bool = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Binding(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Binding.

version = 'v1'
endpoint = 'bindings'
kind = 'Binding'
plural = 'bindings'
singular = 'binding'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ClusterRole(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ClusterRole.

version = 'rbac.authorization.k8s.io/v1'
endpoint = 'clusterroles'
kind = 'ClusterRole'
plural = 'clusterroles'
singular = 'clusterrole'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ClusterRoleBinding(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ClusterRoleBinding.

version = 'rbac.authorization.k8s.io/v1'
endpoint = 'clusterrolebindings'
kind = 'ClusterRoleBinding'
plural = 'clusterrolebindings'
singular = 'clusterrolebinding'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ComponentStatus(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ComponentStatus.

version = 'v1'
endpoint = 'componentstatuses'
kind = 'ComponentStatus'
plural = 'componentstatuses'
singular = 'componentstatus'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ConfigMap(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ConfigMap.

version = 'v1'
endpoint = 'configmaps'
kind = 'ConfigMap'
plural = 'configmaps'
singular = 'configmap'
namespaced = True
property data: box.Box

Data of the ConfigMap.

scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ControllerRevision(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ControllerRevision.

version = 'apps/v1'
endpoint = 'controllerrevisions'
kind = 'ControllerRevision'
plural = 'controllerrevisions'
singular = 'controllerrevision'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.CronJob(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes CronJob.

version = 'batch/v1'
endpoint = 'cronjobs'
kind = 'CronJob'
plural = 'cronjobs'
singular = 'cronjob'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.CustomResourceDefinition(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes CustomResourceDefinition.

version = 'apiextensions.k8s.io/v1'
endpoint = 'customresourcedefinitions'
kind = 'CustomResourceDefinition'
plural = 'customresourcedefinitions'
singular = 'customresourcedefinition'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.DaemonSet(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes DaemonSet.

version = 'apps/v1'
endpoint = 'daemonsets'
kind = 'DaemonSet'
plural = 'daemonsets'
singular = 'daemonset'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Deployment(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Deployment.

version = 'apps/v1'
endpoint = 'deployments'
kind = 'Deployment'
plural = 'deployments'
singular = 'deployment'
namespaced = True
scalable = True
async ready_pods() list[Pod]

Return a list of Pods for this Deployment.

async pods() list[Pod]

Return a list of Pods for this Deployment.

async ready()

Check if the deployment is ready.

scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Endpoints(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Endpoints.

version = 'v1'
endpoint = 'endpoints'
kind = 'Endpoints'
plural = 'endpoints'
singular = 'endpoint'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Event(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Event.

version = 'v1'
endpoint = 'events'
kind = 'Event'
plural = 'events'
singular = 'event'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.HorizontalPodAutoscaler(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes HorizontalPodAutoscaler.

version = 'autoscaling/v2'
endpoint = 'horizontalpodautoscalers'
kind = 'HorizontalPodAutoscaler'
plural = 'horizontalpodautoscalers'
singular = 'horizontalpodautoscaler'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Ingress(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Ingress.

version = 'networking.k8s.io/v1'
endpoint = 'ingresses'
kind = 'Ingress'
plural = 'ingresses'
singular = 'ingress'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.IngressClass(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes IngressClass.

version = 'networking.k8s.io/v1'
endpoint = 'ingressclasses'
kind = 'IngressClass'
plural = 'ingressclasses'
singular = 'ingressclass'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.IPAddress(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes IPAddress.

version = 'networking.k8s.io/v1'
endpoint = 'ipaddresses'
kind = 'IPAddress'
plural = 'ipaddresses'
singular = 'ipaddress'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Job(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Job.

version = 'batch/v1'
endpoint = 'jobs'
kind = 'Job'
plural = 'jobs'
singular = 'job'
namespaced = True
scalable = True
scalable_spec = 'parallelism'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.LimitRange(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes LimitRange.

version = 'v1'
endpoint = 'limitranges'
kind = 'LimitRange'
plural = 'limitranges'
singular = 'limitrange'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Namespace(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Namespace.

version = 'v1'
endpoint = 'namespaces'
kind = 'Namespace'
plural = 'namespaces'
singular = 'namespace'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.NetworkPolicy(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes NetworkPolicy.

version = 'networking.k8s.io/v1'
endpoint = 'networkpolicies'
kind = 'NetworkPolicy'
plural = 'networkpolicies'
singular = 'networkpolicy'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Node(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Node.

version = 'v1'
endpoint = 'nodes'
kind = 'Node'
plural = 'nodes'
singular = 'node'
namespaced = False
property unschedulable
async cordon() None

Cordon the node.

This will mark the node as unschedulable.

async uncordon() None

Uncordon the node.

This will mark the node as schedulable.

async taint(key: str, value: str, *, effect: str) None

Taint a node.

property taints: box.Box

Labels of the Kubernetes resource.

scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.PersistentVolume(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes PersistentVolume.

version = 'v1'
endpoint = 'persistentvolumes'
kind = 'PersistentVolume'
plural = 'persistentvolumes'
singular = 'persistentvolume'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.PersistentVolumeClaim(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes PersistentVolumeClaim.

version = 'v1'
endpoint = 'persistentvolumeclaims'
kind = 'PersistentVolumeClaim'
plural = 'persistentvolumeclaims'
singular = 'persistentvolumeclaim'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Pod(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Pod.

version = 'v1'
endpoint = 'pods'
kind = 'Pod'
plural = 'pods'
singular = 'pod'
namespaced = True
async ready() bool

Check if the pod is ready.

async logs(container=None, pretty=None, previous=False, since_seconds=None, since_time=None, timestamps=False, tail_lines=None, limit_bytes=None, follow=False, timeout=3600) collections.abc.AsyncGenerator[str]
portforward(remote_port: int, local_port: kr8s.portforward.LocalPortType = 'match', address: list[str] | str = '127.0.0.1') kr8s.asyncio.portforward.PortForward

Port forward a pod.

Returns an instance of kr8s.portforward.PortForward for this Pod.

Args:
remote_port:

The port on the Pod to forward to.

local_port:

The local port to listen on. Defaults to "match", which will match the remote_port. Set to "auto" or None to find an available high port. Set to an int to specify a specific port.

address:

List of addresses or address to listen on. Defaults to [“127.0.0.1”], will listen only on 127.0.0.1.

Example:

This can be used as a an async context manager or with explicit start/stop methods.

Context manager:

>>> async with pod.portforward(8888) as port:
...     print(f"Forwarding to port {port}")
...     # Do something with port 8888

Explict start/stop:

>>> pf = pod.portforward(8888)
>>> await pf.start()
>>> print(f"Forwarding to port {pf.local_port}")
>>> # Do something with port 8888
>>> await pf.stop()

Explict bind address:

>>> async with pod.PortForward(8888, address=["127.0.0.1", "10.20.0.1"]) as port:
...     print(f"Forwarding to port {port}")
...     # Do something with port 8888 on the Pod, port will be bind to 127.0.0.1 and 10.20.0.1
async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True)

Run a command in a container and wait until it completes.

Behaves like subprocess.run().

Args:
command:

Command to execute.

container:

Container to execute the command in.

stdin:

If set, read stdin to the container.

stdout:

If set, write stdout to the provided writable stream object.

stderr:

If set, write stderr to the provided writable stream object.

check:

If True, raise an exception if the command fails.

capture_output:

If True, store stdout and stderr from the container in an attribute.

Returns:

A kr8s._exec.CompletedExec object.

Example:
>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> ex = await pod.exec(["ls", "-l"])
>>> print(ex.stdout)
>>> print(ex.stderr)
classmethod gen(*, name=None, generate_name=None, image=None, namespace=None, annotations=None, command=None, env=None, resources=None, image_pull_policy=None, labels=None, ports=None, restart='Always')

Generate a pod definition.

Args:

name (str): The name of the pod. generate_name (str): Template for generating the name of the pod. namespace (str): The namespace of the pod. image (str): The image to use. annotations (dict): Annotations to add to the pod. command (list): Command to run in the container. env (dict): Environment variables to set in the container. resources (dict): Resources to set in the container. image_pull_policy (str): Image pull policy to use. labels (dict): Labels to add to the pod. ports (list|int): Ports to expose. restart (str): Restart policy to use.

Returns:

A kr8s.objects.Pod object.

Example:
>>> from kr8s.objects import Pod
>>> pod = Pod.gen(name="my-pod", image="my-image")
>>> pod.create()

Create an nginx Pod that exposes port 80. >>> from kr8s.objects import Pod >>> pod = Pod.gen(name=”nginx”, image=”nginx:latest”, ports=[80]) >>> pod.create()

Create an wordpress Pod that exposes port 80. >>> from kr8s.objects import Pod >>> pod = Pod.gen(name=”wordpress”, image=”wordpress:latest”, ports=[{“containerPort”: 80}]) >>> pod.create()

Create a Pod that requires a GPU >>> from kr8s.objects import Pod >>> pod = Pod.gen(name=”cuda-vectoradd”, … image=”nvidia/samples:vectoradd-cuda11.6.0-ubuntu18.04”, … resources={“limits”: {“nvidia.com/gpu”: 1}})

async tolerate(key: str, *, operator: str, effect: str, value: str | None = None, toleration_seconds: int | None = None)

Add a toleration to the Pod.

Args:

key (str): Key of the taint to tolerate. operator (str): Toleration operator. effect (str): Specifies the effect of the taint to tolerate. value (str): Value of taint to tolerate. toleration_seconds (str): Toleration seconds.

property tolerations: box.Box

Tolerations for Pod.

scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.PodDisruptionBudget(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes PodDisruptionBudget.

version = 'policy/v1'
endpoint = 'poddisruptionbudgets'
kind = 'PodDisruptionBudget'
plural = 'poddisruptionbudgets'
singular = 'poddisruptionbudget'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.PodTemplate(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes PodTemplate.

version = 'v1'
endpoint = 'podtemplates'
kind = 'PodTemplate'
plural = 'podtemplates'
singular = 'podtemplate'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ReplicaSet(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ReplicaSet.

version = 'apps/v1'
endpoint = 'replicasets'
kind = 'ReplicaSet'
plural = 'replicasets'
singular = 'replicaset'
namespaced = True
scalable = True
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ReplicationController(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ReplicationController.

version = 'v1'
endpoint = 'replicationcontrollers'
kind = 'ReplicationController'
plural = 'replicationcontrollers'
singular = 'replicationcontroller'
namespaced = True
scalable = True
async ready()

Check if the deployment is ready.

scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ResourceQuota(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ResourceQuota.

version = 'v1'
endpoint = 'resourcequotas'
kind = 'ResourceQuota'
plural = 'resourcequotas'
singular = 'resourcequota'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Role(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Role.

version = 'rbac.authorization.k8s.io/v1'
endpoint = 'roles'
kind = 'Role'
plural = 'roles'
singular = 'role'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.RoleBinding(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes RoleBinding.

version = 'rbac.authorization.k8s.io/v1'
endpoint = 'rolebindings'
kind = 'RoleBinding'
plural = 'rolebindings'
singular = 'rolebinding'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Secret(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Secret.

version = 'v1'
endpoint = 'secrets'
kind = 'Secret'
plural = 'secrets'
singular = 'secret'
namespaced = True
property data: box.Box

Data of the Secret.

scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Service(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Service.

version = 'v1'
endpoint = 'services'
kind = 'Service'
plural = 'services'
singular = 'service'
namespaced = True
async proxy_http_request(method: str, path: str, port: int | None = None, **kwargs: Any) httpx.Response

Issue a HTTP request with specific HTTP method to proxy of a Service.

Args:

method: HTTP method to use. path: Path to proxy. port: Port to proxy to. If not specified, the first port in the

Service’s spec will be used.

**kwargs: Additional keyword arguments to pass to the API call.

async proxy_http_get(path: str, port: int | None = None, **kwargs) httpx.Response
async proxy_http_post(path: str, port: int | None = None, **kwargs) None
async proxy_http_put(path: str, port: int | None = None, **kwargs) httpx.Response
async proxy_http_delete(path: str, port: int | None = None, **kwargs) httpx.Response
async ready_pods() list[Pod]

Return a list of ready Pods for this Service.

async ready() bool

Check if the service is ready.

portforward(remote_port: int, local_port: kr8s.portforward.LocalPortType = 'match', address: str | list[str] = '127.0.0.1') kr8s.asyncio.portforward.PortForward

Port forward a service.

Returns an instance of kr8s.portforward.PortForward for this Service.

Args:
remote_port:

The port on the Pod to forward to.

local_port:

The local port to listen on. Defaults to "match", which will match the remote_port. Set to "auto" or None to find an available high port. Set to an int to specify a specific port.

address:

List of addresses or address to listen on. Defaults to [“127.0.0.1”], will listen only on 127.0.0.1.

Example:

This can be used as a an async context manager or with explicit start/stop methods.

Context manager:

>>> async with service.portforward(8888) as port:
...     print(f"Forwarding to port {port}")
...     # Do something with port 8888

Explict start/stop:

>>> pf = service.portforward(8888)
>>> await pf.start()
>>> print(f"Forwarding to port {pf.local_port}")
>>> # Do something with port 8888
>>> await pf.stop()
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ServiceAccount(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ServiceAccount.

version = 'v1'
endpoint = 'serviceaccounts'
kind = 'ServiceAccount'
plural = 'serviceaccounts'
singular = 'serviceaccount'
namespaced = True
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.ServiceCIDR(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes ServiceCIDR.

version = 'networking.k8s.io/v1'
endpoint = 'servicecidrs'
kind = 'ServiceCIDR'
plural = 'servicecidrs'
singular = 'servicecidr'
namespaced = False
scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.StatefulSet(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes StatefulSet.

version = 'apps/v1'
endpoint = 'statefulsets'
kind = 'StatefulSet'
plural = 'statefulsets'
singular = 'statefulset'
namespaced = True
scalable = True
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

class kr8s.asyncio.objects.Table(resource: kr8s._types.SpecType, namespace: str | None = None, api: kr8s._api.Api | None = None)

Bases: APIObject

A Kubernetes Table.

version = 'meta.k8s.io/v1'
endpoint = 'tables'
kind = 'Table'
plural = 'tables'
singular = 'table'
namespaced = False
property rows: list[dict]

Table rows.

property column_definitions: list[dict]

Table column definitions.

scalable: bool = False
scalable_spec: str = 'replicas'
property api
property raw: box.Box

Raw object returned from the Kubernetes API.

property name: str

Name of the Kubernetes resource.

property namespace: str | None

Namespace of the Kubernetes resource.

property metadata: box.Box

Metadata of the Kubernetes resource.

property spec: box.Box

Spec of the Kubernetes resource.

property status: box.Box

Status of the Kubernetes resource.

property labels: box.Box

Labels of the Kubernetes resource.

property annotations: box.Box

Annotations of the Kubernetes resource.

property replicas: int

Replicas of the Kubernetes resource.

classmethod get(name: str | None = None, namespace: str | None = None, api: kr8s._api.Api | None = None, label_selector: str | dict[str, str] | None = None, field_selector: str | dict[str, str] | None = None, timeout: int = 2, **kwargs) typing_extensions.Self
Async:

Get a Kubernetes resource by name or via selectors.

async exists(ensure=False) bool

Check if this object exists in Kubernetes.

async create() None

Create this object in Kubernetes.

async delete(propagation_policy: str | None = None, grace_period: int | None = None, force: bool = False) None

Delete this object from Kubernetes.

Args:

propagation_policy: The deletion propagation policy. grace_period: The grace period for deletion. force: Force deletion. (Setting to True is equivelaent to setting grace_period to 0)

async refresh() None

Refresh this object from Kubernetes.

async patch(patch, *, subresource=None, type=None) None

Patch this object in Kubernetes.

async scale(replicas: int | None = None) None

Scale this object in Kubernetes.

async exec(command: list[str], *, container: str | None = None, stdin: str | BinaryIO | None = None, stdout: BinaryIO | None = None, stderr: BinaryIO | None = None, check: bool = True, capture_output: bool = True) kr8s._exec.Exec

Execute a command in this object.

async watch() collections.abc.AsyncGenerator[tuple[str, typing_extensions.Self]]

Watch this object in Kubernetes.

async wait(conditions: list[str] | str, mode: Literal['any', 'all'] = 'any', timeout: int | None = None)

Wait for conditions to be met.

Args:

conditions: A list of conditions to wait for. mode: Match any condition with “any” or all conditions with “all”. Defaults to “any”. timeout: Timeout in seconds.

Example:

Wait for a Pod to be ready.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait("condition=Ready")

Wait for a Job to either succeed or fail.

>>> from kr8s.objects import Job
>>> job = Job.get("my-jod")
>>> job.wait(["condition=Complete", "condition=Failed"])

Wait for a Pod to be initialized and ready to start containers.

>>> from kr8s.objects import Pod
>>> pod = Pod.get("my-pod")
>>> pod.wait(["condition=Initialized", "condition=PodReadyToStartContainers"], mode="all")
Note:

As of the current Kubertenetes release when this function was written (1.29) kubectl doesn’t support multiple conditions. There is a PR to implement this but it hasn’t been merged yet https://github.com/kubernetes/kubernetes/pull/119205.

Given that for is a reserved word anyway we can’t exactly match the kubectl API so we use condition in combination with a mode instead.

async annotate(annotations: dict | None = None, **kwargs) None

Annotate this object in Kubernetes.

async label(*labels: dict | str, **kwargs) None

Add labels to this object in Kubernetes.

Labels can be passed as a dictionary or as keyword arguments.

Args:
labels:

A dictionary of labels to set or string to remove.

**kwargs:

Labels to set.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Both of these are equivalent
>>> deployment.label({"app": "my-app"})
>>> deployment.label(app="my-app")
>>> # You can also remove a label by passing it's name with a `-` on the end
>>> deployment.label("app-")
async remove_label(*labels: str) None

Remove labels from this object in Kubernetes.

Labels can be passed as a list of strings.

Args:

labels: A list of labels to remove.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> deployment.remove_label("app")
keys() list

Return the keys of this object.

async set_owner(owner: APIObject) None

Set the owner reference of this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

owner: The owner object to set a reference to.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> pod.set_owner(deployment)
async adopt(child: APIObject) None

Adopt this object.

This will set the owner reference of the child object to this object.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

Args:

child: The child object to adopt.

Example:
>>> from kr8s.objects import Deployment, Pod
>>> deployment = Deployment.get("my-deployment")
>>> pod = Pod.get("my-pod")
>>> deployment.adopt(pod)
to_dict() dict

Return a dictionary representation of this object.

to_yaml() str

Return a YAML representation of this object.

to_lightkube() Any

Return a lightkube representation of this object.

to_pykube(api) Any

Return a pykube representation of this object.

Args:

api: A pykube API object.

Example:
>>> from kr8s.objects import Deployment
>>> deployment = Deployment.get("my-deployment")
>>> # Create a pykube API object
>>> from pykube import HTTPClient
>>> api = HTTPClient()
>>> pykube_deployment = deployment.to_pykube(api)
pprint(use_rich: bool = True, theme: str = 'ansi_dark') None

Pretty print this object to stdout.

Prints the object as YAML (using rich for syntax highlighting if available).

Args:

use_rich: Use rich to pretty print. If rich` is not installed this will be ignored. theme: The ``pygments theme for rich to use. Defaults to “ansi_dark” to use default terminal colors.

classmethod gen(*args, **kwargs)
Abstractmethod:

classmethod list(**kwargs) collections.abc.AsyncGenerator[typing_extensions.Self]
Async:

List objects in Kubernetes.

Args:

api: An optional API object to use. **kwargs: Keyword arguments to pass to kr8s.get().

Returns:

A list of objects.

kr8s.asyncio.objects.get_class(kind: str, version: str | None = None, _asyncio: bool = True) type[APIObject]

Get an APIObject subclass by kind and version.

Args:

kind: The Kubernetes resource kind. version: The Kubernetes API group/version.

Returns:

An APIObject subclass.

Raises:

KeyError: If no object is registered for the given kind and version.

kr8s.asyncio.objects.new_class(kind: str, version: str | None = None, asyncio: bool = True, namespaced=True, scalable: bool | None = None, scalable_spec: str | None = None, plural: str | None = None) type[APIObject]

Create a new APIObject subclass.

Args:

kind: The Kubernetes resource kind. version: The Kubernetes API version. asyncio: Whether to use asyncio or not. namespaced: Whether the resource is namespaced or not. scalable: Whether the resource is scalable or not. scalable_spec: The name of the field to use for scaling. plural: The plural form of the resource.

Returns:

A new APIObject subclass.

async kr8s.asyncio.objects.object_from_name_type(name: str, namespace: str | None = None, api: kr8s._api.Api | None = None, _asyncio: bool = True) APIObject

Create an APIObject from a Kubernetes resource name.

Args:

name: A Kubernetes resource name. namespace: The namespace of the resource. api: An optional API instance to use. _asyncio: Whether to use asyncio or not.

Returns:

A corresponding APIObject subclass instance.

Raises:

ValueError: If the resource kind or API version is not supported.

kr8s.asyncio.objects.object_from_spec(spec: dict, api: kr8s._api.Api | None = None, allow_unknown_type: bool = False, _asyncio: bool = True) APIObject

Create an APIObject from a Kubernetes resource spec.

Args:

spec: A Kubernetes resource spec. api: An optional API instance to use. allow_unknown_type: Whether to allow unknown resource types. _asyncio: Whether to use asyncio or not.

Returns:

A corresponding APIObject subclass instance.

Raises:

ValueError: If the resource kind or API version is not supported.

async kr8s.asyncio.objects.objects_from_files(path: str | pathlib.Path, api: kr8s._api.Api | None = None, recursive: bool = False, _asyncio: bool = True) list[APIObject]

Create APIObjects from Kubernetes resource files.

Args:

path: A path to a Kubernetes resource file or directory of resource files. api: An optional API instance to use. recursive: Whether to recursively search for resource files in subdirectories. _asyncio: Whether to use asyncio or not.

Returns:

A list of APIObject subclass instances.

Raises:

ValueError: If the resource kind or API version is not supported.