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 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.Optional duration in seconds the pod may be active before the system tries to mark it failed and kill associated containers
Affinity scheduling rules for the pod
Whether a service account token should be automatically mounted
DNS parameters for the pod
DNS policy for the pod. Valid values:
ClusterFirst, ClusterFirstWithHostNet, Default, NoneWhether information about services should be injected into pod’s environment variables
List of ephemeral containers for debugging
Optional list of hosts and IPs to inject into the pod’s hosts file
Use the host’s IPC namespace
Use the host’s network namespace
Use the host’s PID namespace
Use the host’s user namespace
Hostname of the pod
List of references to secrets for pulling images
List of initialization containers executed before main containers
NodeName indicates which node this pod is scheduled on
Selector which must match a node’s labels for the pod to be scheduled on that node
OS parameters of the pod
Resource overhead associated with running a pod
Policy for preempting pods with lower priority. Values:
Never, PreemptLowerPriorityPriority value for the pod
Priority class name (e.g.,
system-node-critical, system-cluster-critical)Readiness gates for pod readiness evaluation
ResourceClaims that must be allocated before the pod starts
Compute resource requirements
Restart policy for containers. Values:
Always, OnFailure, NeverRuntimeClass name to use for running this pod
Name of the scheduler to dispatch this pod
SchedulingGates that block pod scheduling
Pod-level security attributes
Deprecated alias for service_account_name
Name of the ServiceAccount to use
If true, the pod’s hostname will be configured as the pod’s FQDN
Share a single process namespace between all containers
Subdomain for the pod’s fully qualified hostname
Duration in seconds the pod needs to terminate gracefully
Pod’s tolerations
How pods should spread across topology domains
List of volumes that can be mounted by containers
Methods
execute
Execute a command in the pod.Command to run in the pod
Time to wait for the command to complete
Container name where to exec the command. If empty, uses the first container.
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