Skip to main content

Overview

The Pod class represents a Kubernetes Pod - a collection of one or more containers that run on a host. Pods are the smallest deployable units in Kubernetes and are scheduled onto nodes by the scheduler.

Class Definition

API Version: v1

Constructor

Pod accepts all parameters from NamespacedResource, plus:
list[Any]
required
List of containers belonging to the pod. Must contain at least one container. Each container should be a dictionary with keys like name, image, command, etc.
int | None
Optional duration in seconds the pod may be active before the system tries to mark it failed and kill associated containers
dict[str, Any] | None
Affinity scheduling rules for the pod
bool | None
Whether a service account token should be automatically mounted
dict[str, Any] | None
DNS parameters for the pod
str | None
DNS policy for the pod. Valid values: ClusterFirst, ClusterFirstWithHostNet, Default, None
Whether information about services should be injected into pod’s environment variables
list[Any] | None
List of ephemeral containers for debugging
list[Any] | None
Optional list of hosts and IPs to inject into the pod’s hosts file
bool | None
Use the host’s IPC namespace
bool | None
Use the host’s network namespace
bool | None
Use the host’s PID namespace
bool | None
Use the host’s user namespace
str | None
Hostname of the pod
list[Any] | None
List of references to secrets for pulling images
list[Any] | None
List of initialization containers executed before main containers
str | None
NodeName indicates which node this pod is scheduled on
dict[str, Any] | None
Selector which must match a node’s labels for the pod to be scheduled on that node
dict[str, Any] | None
OS parameters of the pod
dict[str, Any] | None
Resource overhead associated with running a pod
str | None
Policy for preempting pods with lower priority. Values: Never, PreemptLowerPriority
int | None
Priority value for the pod
str | None
Priority class name (e.g., system-node-critical, system-cluster-critical)
list[Any] | None
Readiness gates for pod readiness evaluation
list[Any] | None
ResourceClaims that must be allocated before the pod starts
dict[str, Any] | None
Compute resource requirements
str | None
Restart policy for containers. Values: Always, OnFailure, Never
str | None
RuntimeClass name to use for running this pod
str | None
Name of the scheduler to dispatch this pod
list[Any] | None
SchedulingGates that block pod scheduling
dict[str, Any] | None
Pod-level security attributes
str | None
Deprecated alias for service_account_name
str | None
Name of the ServiceAccount to use
bool | None
If true, the pod’s hostname will be configured as the pod’s FQDN
bool | None
Share a single process namespace between all containers
str | None
Subdomain for the pod’s fully qualified hostname
int | None
Duration in seconds the pod needs to terminate gracefully
list[Any] | None
Pod’s tolerations
list[Any] | None
How pods should spread across topology domains
list[Any] | None
List of volumes that can be mounted by containers

Methods

execute

Execute a command in the pod.
list[str]
required
Command to run in the pod
int
default:"60"
Time to wait for the command to complete
str
default:"''"
Container name where to exec the command. If empty, uses the first container.
bool
default:"False"
If True, ignore error return code and return output anyway
Returns: Command output as string Raises: ExecOnPodError if the command failed

log

Get pod logs.
Returns: Pod logs as string Accepts all kwargs supported by Kubernetes API for reading pod logs, such as:
  • container: Container name
  • follow: Follow the log stream
  • previous: Get logs from previous container instance
  • since_seconds: Relative time in seconds
  • tail_lines: Number of lines from the end
  • timestamps: Include timestamps

Properties

node

Get the Node object where the pod is running. Returns: Node object

ip

Get the pod’s IP address. Returns: Pod IP as string

Inherited Methods

Pod inherits all methods from NamespacedResource and Resource.

Examples

Creating a Simple Pod

Creating a Pod with Multiple Containers

Executing Commands in a Pod

Getting Pod Logs

Pod with Resource Limits

Pod with Volume Mounts

Pod with Node Selector

Waiting for Pod to be Ready

Using Context Manager

See Also