Pods & Containers
A Pod is the smallest deployable unit in Kubernetes: one or more containers sharing a network namespace, an IP and optional volumes. Master pod manifests, init containers, sidecars, probes and the classic pod failure states.
What is this?
A Pod is the smallest deployable unit in Kubernetes: a group of one or more containers that share a network namespace (one IP), loopback, IPC and optionally storage volumes. Containers in a pod are always co-located on the same node and can talk to each other over localhost. The pod is the unit of scheduling, scaling and lifecycle management.
Why do you need it?
- A Pod gives a stable identity and a shared IP to a microservice even as individual containers restart underneath it.
- Multi-container pods enable the sidecar pattern: logging agents, proxies and watchers that extend a main container.
- Init containers run setup tasks to completion before application containers start.
- Probes (liveness, readiness, startup) let the platform keep restarts and traffic honest.
Mental model
A building with rooms sharing one street address
A Pod
Every room (container) has its own interior, but all rooms share the front door (IP), the plumbing (volumes) and the address, and they must be built on the same lot (node).
How it works
- You declare a Pod manifest: containers, image, ports, probes, resource requests and limits, and volumes.
- The scheduler binds the pod to a node; the kubelet pulls the images and starts the containers in order.
- Containers in a pod share the network namespace, so they see localhost and share a single cluster IP.
- The kubelet restarts containers according to restartPolicy; the default of Always is what Deployments rely on.
- When a pod finishes or fails it is deleted and, if owned by a controller such as a Deployment, recreated by that controller.
From manifest to running pod with health checks.
Key commands
kubectl run web --image=nginx:1.25 --restart=NeverCreate a single Pod imperatively (the --restart=Never flag is what makes it a Pod, not a Deployment).
kubectl get pods -o wideList pods with the node and pod IP columns.
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES web 1/1 Running 0 3m 10.244.0.5 minikube <none> <none>
kubectl describe pod webShow detailed status, conditions and recent events for a pod.
kubectl logs web --previousRead the logs of a crashed container instance (before the restart).
kubectl exec -it web -- /bin/shOpen a shell inside a running container.
kubectl port-forward pod/web 8080:80Tunnel a local port to a pod port for debugging without exposing a Service.
Examples
A pod with an init container, shared volume and probes
apiVersion: v1kind: Podmetadata: name: web labels: app: webspec: restartPolicy: Always initContainers: - name: init image: busybox:1.36 command: ["sh", "-c", "echo ready > /workdir/ready.txt"] volumeMounts: - name: workdir mountPath: /workdir containers: - name: nginx image: nginx:1.25 ports: - containerPort: 80 volumeMounts: - name: workdir mountPath: /usr/share/nginx/html resources: requests: cpu: 100m memory: 64Mi limits: memory: 128Mi livenessProbe: httpGet: path: / port: 80 volumes: - name: workdir emptyDir: {}The init container runs first and writes a file into the shared emptyDir volume. Only after it exits successfully does the kubelet start the nginx container, which mounts the same directory. The liveness probe restarts nginx if the HTTP endpoint stops responding, and the resource requests reserve capacity on the node.
In production
- One microservice per pod, with sidecars for logging, metrics or mTLS proxies that share the pod lifecycle.
- Init containers prepare data directories, run schema migrations or wait for dependencies before the app starts.
- Readiness probes remove unhealthy pods from Service endpoints; liveness probes restart wedged containers.
- Resource requests reserve capacity and limits protect the node from noisy neighbors.
Best practices
- Run one main container per pod; add sidecars only when they must share the pod lifecycle.
- Always set liveness and readiness probes plus resource requests and limits on production containers.
- Treat pods as ephemeral: write durable data to volumes, never to the container filesystem.
- Label every pod so Services and controllers can select them reliably.
Common mistakes
- Bundling several independent apps in one pod, forcing them to scale and restart together.
- Running the app as root inside the container instead of a non-root user.
- Forgetting imagePullSecrets for private registries, which causes ImagePullBackOff.
- Misconfiguring probes so readiness failures silently remove healthy traffic.
Common issues
ImagePullBackOffKubernetes cannot pull the container image: wrong tag, private registry without credentials, or rate limiting.
Verify the image and tag, test the pull locally, and add imagePullSecrets for private registries.
CrashLoopBackOffThe container starts and exits repeatedly, often a missing dependency, bad config or immediate error.
Run kubectl logs <pod> --previous and kubectl describe pod <pod> to read the crash output and events.
CreateContainerConfigErrorThe container spec references a missing ConfigMap or Secret key, or an invalid volume name.
Inspect the pod events with kubectl describe, then create the missing object or fix the key reference.
Debugging tips
- kubectl describe pod <name> shows events for scheduling, image pull, container start and failures.
- kubectl logs <pod> --previous reads output from the crashed container instance.
- kubectl exec -it <pod> -- /bin/sh lets you inspect the live container.
- kubectl get pods --show-labels verifies that Service selectors match pod labels.
Interview checkpoint
Hands-on lab
- Create a Pod from a manifest and with kubectl run
- Inspect pod status, IP and events
- Exec into a running container and port-forward
- Reproduce and diagnose a CrashLoopBackOff
Run and Debug Your First Pod
25 min ยท beginner
Quick quiz
What is the smallest deployable unit in Kubernetes?
Containers inside the same Pod share an IP address and network namespace.
Which restartPolicy do Deployments require for their pods?
Cheat sheet
kubectl run web --image=nginx --restart=NeverCreate a single podkubectl get pods -o wideList pods with IP and nodekubectl describe pod NAMEStatus, conditions, eventskubectl logs NAME --previousLogs of crashed instancekubectl exec -it NAME -- /bin/shShell into a containerkubectl port-forward pod/NAME 8080:80Local tunnel to the pod