Overview
ThePod 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
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, Nonebool | 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, PreemptLowerPriorityint | 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, Neverstr | 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
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
ExecOnPodError if the command failed
log
Get pod logs.container: Container namefollow: Follow the log streamprevious: Get logs from previous container instancesince_seconds: Relative time in secondstail_lines: Number of lines from the endtimestamps: Include timestamps
Properties
node
ip
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
- NamespacedResource - Base class
- Deployment - For managing pod replicas
- Service - For exposing pods
- ConfigMap - For configuration data
- Secret - For sensitive data