> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/RedHatQE/openshift-python-wrapper/llms.txt
> Use this file to discover all available pages before exploring further.

# Pod

> Pod resource for running containers in Kubernetes/OpenShift

## 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

```python theme={null}
from ocp_resources.pod import Pod
```

**API Version:** `v1`

## Constructor

Pod accepts all parameters from [NamespacedResource](/api-reference/namespaced-resource), plus:

<ParamField path="containers" type="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.
</ParamField>

<ParamField path="active_deadline_seconds" type="int | None">
  Optional duration in seconds the pod may be active before the system tries to mark it failed and kill associated containers
</ParamField>

<ParamField path="affinity" type="dict[str, Any] | None">
  Affinity scheduling rules for the pod
</ParamField>

<ParamField path="automount_service_account_token" type="bool | None">
  Whether a service account token should be automatically mounted
</ParamField>

<ParamField path="dns_config" type="dict[str, Any] | None">
  DNS parameters for the pod
</ParamField>

<ParamField path="dns_policy" type="str | None">
  DNS policy for the pod. Valid values: `ClusterFirst`, `ClusterFirstWithHostNet`, `Default`, `None`
</ParamField>

<ParamField path="enable_service_links" type="bool | None">
  Whether information about services should be injected into pod's environment variables
</ParamField>

<ParamField path="ephemeral_containers" type="list[Any] | None">
  List of ephemeral containers for debugging
</ParamField>

<ParamField path="host_aliases" type="list[Any] | None">
  Optional list of hosts and IPs to inject into the pod's hosts file
</ParamField>

<ParamField path="host_ipc" type="bool | None">
  Use the host's IPC namespace
</ParamField>

<ParamField path="host_network" type="bool | None">
  Use the host's network namespace
</ParamField>

<ParamField path="host_pid" type="bool | None">
  Use the host's PID namespace
</ParamField>

<ParamField path="host_users" type="bool | None">
  Use the host's user namespace
</ParamField>

<ParamField path="hostname" type="str | None">
  Hostname of the pod
</ParamField>

<ParamField path="image_pull_secrets" type="list[Any] | None">
  List of references to secrets for pulling images
</ParamField>

<ParamField path="init_containers" type="list[Any] | None">
  List of initialization containers executed before main containers
</ParamField>

<ParamField path="node_name" type="str | None">
  NodeName indicates which node this pod is scheduled on
</ParamField>

<ParamField path="node_selector" type="dict[str, Any] | None">
  Selector which must match a node's labels for the pod to be scheduled on that node
</ParamField>

<ParamField path="os" type="dict[str, Any] | None">
  OS parameters of the pod
</ParamField>

<ParamField path="overhead" type="dict[str, Any] | None">
  Resource overhead associated with running a pod
</ParamField>

<ParamField path="preemption_policy" type="str | None">
  Policy for preempting pods with lower priority. Values: `Never`, `PreemptLowerPriority`
</ParamField>

<ParamField path="priority" type="int | None">
  Priority value for the pod
</ParamField>

<ParamField path="priority_class_name" type="str | None">
  Priority class name (e.g., `system-node-critical`, `system-cluster-critical`)
</ParamField>

<ParamField path="readiness_gates" type="list[Any] | None">
  Readiness gates for pod readiness evaluation
</ParamField>

<ParamField path="resource_claims" type="list[Any] | None">
  ResourceClaims that must be allocated before the pod starts
</ParamField>

<ParamField path="resources" type="dict[str, Any] | None">
  Compute resource requirements
</ParamField>

<ParamField path="restart_policy" type="str | None">
  Restart policy for containers. Values: `Always`, `OnFailure`, `Never`
</ParamField>

<ParamField path="runtime_class_name" type="str | None">
  RuntimeClass name to use for running this pod
</ParamField>

<ParamField path="scheduler_name" type="str | None">
  Name of the scheduler to dispatch this pod
</ParamField>

<ParamField path="scheduling_gates" type="list[Any] | None">
  SchedulingGates that block pod scheduling
</ParamField>

<ParamField path="security_context" type="dict[str, Any] | None">
  Pod-level security attributes
</ParamField>

<ParamField path="service_account" type="str | None">
  Deprecated alias for service\_account\_name
</ParamField>

<ParamField path="service_account_name" type="str | None">
  Name of the ServiceAccount to use
</ParamField>

<ParamField path="set_hostname_as_fqdn" type="bool | None">
  If true, the pod's hostname will be configured as the pod's FQDN
</ParamField>

<ParamField path="share_process_namespace" type="bool | None">
  Share a single process namespace between all containers
</ParamField>

<ParamField path="subdomain" type="str | None">
  Subdomain for the pod's fully qualified hostname
</ParamField>

<ParamField path="termination_grace_period_seconds" type="int | None">
  Duration in seconds the pod needs to terminate gracefully
</ParamField>

<ParamField path="tolerations" type="list[Any] | None">
  Pod's tolerations
</ParamField>

<ParamField path="topology_spread_constraints" type="list[Any] | None">
  How pods should spread across topology domains
</ParamField>

<ParamField path="volumes" type="list[Any] | None">
  List of volumes that can be mounted by containers
</ParamField>

## Methods

### execute

Execute a command in the pod.

```python theme={null}
def execute(
    self,
    command: list[str],
    timeout: int = 60,
    container: str = "",
    ignore_rc: bool = False
) -> str
```

<ParamField path="command" type="list[str]" required>
  Command to run in the pod
</ParamField>

<ParamField path="timeout" type="int" default="60">
  Time to wait for the command to complete
</ParamField>

<ParamField path="container" type="str" default="''">
  Container name where to exec the command. If empty, uses the first container.
</ParamField>

<ParamField path="ignore_rc" type="bool" default="False">
  If True, ignore error return code and return output anyway
</ParamField>

**Returns:** Command output as string

**Raises:** `ExecOnPodError` if the command failed

### log

Get pod logs.

```python theme={null}
def log(self, **kwargs: Any) -> str
```

**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

```python theme={null}
@property
def node(self) -> Node
```

Get the Node object where the pod is running.

**Returns:** Node object

### ip

```python theme={null}
@property
def ip(self) -> str
```

Get the pod's IP address.

**Returns:** Pod IP as string

## Inherited Methods

Pod inherits all methods from [NamespacedResource](/api-reference/namespaced-resource) and [Resource](/api-reference/resource).

## Examples

### Creating a Simple Pod

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="my-pod",
    namespace="default",
    containers=[{
        "name": "nginx",
        "image": "nginx:latest",
        "ports": [{"containerPort": 80}]
    }]
)
pod.create(wait=True)

print(f"Pod {pod.name} created with IP: {pod.ip}")
```

### Creating a Pod with Multiple Containers

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="multi-container-pod",
    namespace="default",
    containers=[
        {
            "name": "nginx",
            "image": "nginx:latest",
            "ports": [{"containerPort": 80}]
        },
        {
            "name": "sidecar",
            "image": "busybox:latest",
            "command": ["sh", "-c", "while true; do sleep 30; done"]
        }
    ]
)
pod.create()
```

### Executing Commands in a Pod

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="my-pod",
    namespace="default"
)

# Execute a command
output = pod.execute(command=["ls", "-la", "/"])
print(output)

# Execute in specific container
output = pod.execute(
    command=["cat", "/etc/hostname"],
    container="nginx"
)
print(output)
```

### Getting Pod Logs

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(client=client, name="my-pod", namespace="default")

# Get all logs
logs = pod.log()
print(logs)

# Get logs from specific container
logs = pod.log(container="nginx")

# Get last 100 lines with timestamps
logs = pod.log(tail_lines=100, timestamps=True)
```

### Pod with Resource Limits

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="limited-pod",
    namespace="default",
    containers=[{
        "name": "nginx",
        "image": "nginx:latest",
        "resources": {
            "requests": {
                "memory": "64Mi",
                "cpu": "250m"
            },
            "limits": {
                "memory": "128Mi",
                "cpu": "500m"
            }
        }
    }]
)
pod.create()
```

### Pod with Volume Mounts

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="pod-with-volume",
    namespace="default",
    containers=[{
        "name": "nginx",
        "image": "nginx:latest",
        "volumeMounts": [{
            "name": "config-volume",
            "mountPath": "/etc/config"
        }]
    }],
    volumes=[{
        "name": "config-volume",
        "configMap": {
            "name": "my-config"
        }
    }]
)
pod.create()
```

### Pod with Node Selector

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="scheduled-pod",
    namespace="default",
    containers=[{
        "name": "nginx",
        "image": "nginx:latest"
    }],
    node_selector={
        "disktype": "ssd",
        "kubernetes.io/hostname": "node-1"
    }
)
pod.create()
```

### Waiting for Pod to be Ready

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

pod = Pod(
    client=client,
    name="my-pod",
    namespace="default",
    containers=[{"name": "nginx", "image": "nginx:latest"}]
)
pod.create()

# Wait for pod to be running
pod.wait_for_status(status="Running", timeout=300)

# Or wait for Ready condition
pod.wait_for_condition(condition="Ready", status="True", timeout=300)

print(f"Pod is running on node: {pod.node.name}")
```

### Using Context Manager

```python theme={null}
from ocp_resources.pod import Pod
from ocp_resources.resource import get_client

client = get_client()

with Pod(
    client=client,
    name="temp-pod",
    namespace="default",
    containers=[{"name": "busybox", "image": "busybox:latest", "command": ["sleep", "3600"]}],
    wait_for_resource=True
) as pod:
    output = pod.execute(command=["echo", "Hello from pod"])
    print(output)
    # Pod is automatically deleted when exiting this block
```

## See Also

* [NamespacedResource](/api-reference/namespaced-resource) - Base class
* [Deployment](/api-reference/deployment) - For managing pod replicas
* [Service](/api-reference/service) - For exposing pods
* [ConfigMap](/api-reference/configmap) - For configuration data
* [Secret](/api-reference/secret) - For sensitive data
