Skip to main content

Pod

A Pod is the smallest deployable unit in Kubernetes: one or more containers that share a network identity, storage volumes, and lifecycle. Every container runs inside a pod, and every pod gets its own IP address in the cluster.

Why pods exist

Some processes must run together, such as an app and a log shipper. Putting them in one pod gives them the same IP and localhost network, and lets them share volumes. Kubernetes schedules, scales, and restarts the pod as one unit.

flowchart TD subgraph Pod["Pod 10.244.1.15"] A["nginx container"] -->|"writes logs"| V[("shared volume")] V -->|"reads logs"| F["fluent-bit sidecar"] end N["Worker node"] --> Pod classDef app fill:#D1FAE5,color:#1E293B classDef store fill:#FFEDD5,color:#1E293B classDef sidecar fill:#DBEAFE,color:#1E293B classDef node fill:#475569,color:#ffffff class A app class V store class F sidecar class N node

Pod lifecycle phases

Phase Meaning
Pending Accepted, waiting for scheduling or image pull
Running Bound to a node, at least one container running
Succeeded All containers exited with 0
Failed A container exited non-zero and will not restart
Unknown Node contact lost

A pod spec

YAML
apiVersion: v1
kind: Pod
metadata:
name: payment-api
namespace: production
labels:
app: payment-api
spec:
containers:
- name: payment-api
image: registry.example.com/payment-api:v3.1.0
ports:
- containerPort: 8080
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-credentials
key: password
resources:
requests: { cpu: "250m", memory: "256Mi" }
limits: { memory: "512Mi" }
readinessProbe:
httpGet: { path: /health, port: 8080 }
restartPolicy: Always
automountServiceAccountToken: false

Multi-container patterns

  • Sidecar: extends the main container, for example log shipping or a mesh proxy.
  • Init container: runs to completion before the app starts, for migrations or waiting on dependencies.

Inspect

Bash
kubectl get pods -n production -o wide
kubectl describe pod payment-api -n production
kubectl logs payment-api -n production --previous
kubectl exec -it payment-api -n production -- sh
Status First step
Pending describe pod, read Events
ImagePullBackOff Check image and credentials
CrashLoopBackOff logs --previous
Evicted describe node for pressure
Remember

A pod with an IP is not necessarily ready. Traffic flows only once the readiness probe passes.

Security

Pods get a ServiceAccount token by default. If the app does not call the Kubernetes API, set automountServiceAccountToken: false.

Common Mistake

Creating bare pods in production. If the node dies, the pod is gone. Use a Deployment, StatefulSet, or Job.

Frequently Asked Questions

Why does Kubernetes use pods instead of scheduling containers directly?

Tightly coupled containers need to share networking and storage and be scheduled and restarted together. The pod is the atomic scheduling unit even when it holds a single container.

Can I rely on a pod's IP address?

No. It changes whenever the pod is recreated. Address pods through a Service, which provides a stable virtual IP and DNS name.

What is the difference between init containers and sidecars?

Init containers run to completion before the main containers start. Sidecars run alongside the main containers for the pod's lifetime.

Found a mistake, an outdated step or a broken link?