Pod Fundamentals

The smallest deployable unit in Kubernetes. Understanding Pods is foundational — everything in K8s (Deployments, ReplicaSets, DaemonSets) ultimately manages Pods. Source: CKA Day 25

Source: CKA Day 7 — Pod Explained

What is a Pod?

A Pod is the smallest and simplest unit in the Kubernetes object model. It represents a single instance of a running process in your cluster.

Multi-Container Pods

A Pod can contain one or more containers that share:

  • Network namespace (same IP address and port space)
  • Storage volumes (shared filesystems)
  • Linux namespaces (ipc, uts)

Containers in the same Pod are always co-located and co-scheduled on the same node.

Best practice: Use 1 container per Pod, except for sidecar patterns (logging, proxy, git sync).

Imperative vs Declarative

Imperative (kubectl commands)

Directly manage resources via CLI — fast for experiments, not reproducible.

CommandPurpose
kubectl run nginx --image=nginxCreate a Pod
kubectl get podsList pods
kubectl get pods -o wideList with node/IP details
kubectl describe pod nginxDetailed pod info
kubectl delete pod nginxDelete a pod
kubectl exec -it nginx -- /bin/shInteractive shell
kubectl logs nginxView logs
kubectl logs nginx --previousView logs from previous container instance (post-crash)
kubectl logs nginx -c sidecarView logs from a specific container in a multi-container Pod

Declarative (YAML manifests)

Define desired state in YAML — version controlled, auditable, GitOps-friendly.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  labels:
    app: web
spec:
  containers:
  - name: nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80
kubectl apply -f pod.yaml
kubectl delete -f pod.yaml

Key YAML Fields

FieldDescription
apiVersionAPI version (v1 for Pod)
kindObject type (Pod, Deployment, Service, etc.)
metadataIdentification data (name, namespace, labels, annotations)
specDesired state specification
spec.containersContainers to run in the Pod
spec.containers[].nameContainer name
spec.containers[].imageDocker image
spec.containers[].portsExposed ports
spec.containers[].resourcesCPU/memory requests and limits for scheduling and runtime guardrails
spec.serviceAccountNameThe ServiceAccount identity this Pod uses for API server authentication (defaults to default)
spec.volumesVolumes available to all containers in the Pod (emptyDir, hostPath, PVC, ConfigMap, Secret)
spec.containers[].volumeMountsMounts a named volume into a container filesystem path

Resource Requests and Limits

Each container can declare resource requests and limits. Requests tell the scheduler how much CPU/memory to reserve when placing the Pod on a node. Limits cap runtime consumption; if a container exceeds its memory limit, it is killed with OOMKilled rather than exhausting the whole node. This is why resource settings belong under spec.containers[], not at the Pod root. Source: CKA Day 16

Pod Lifecycle

PhaseDescription
PendingAccepted by cluster, containers not yet running
RunningBound to node, at least one container running
SucceededAll containers terminated successfully
FailedAll containers terminated, at least one failed
UnknownState cannot be determined

Pod IP Ephemerality

Every Pod receives a unique internal IP address. However, this IP is not stable — it changes on every restart, reschedule, or replacement.

# Original Pod IP
kubectl describe pod nginx-deploy-abc123 | grep IP
# IP: 10.244.1.2
 
# Delete and recreate the Pod
kubectl delete pod nginx-deploy-abc123
 
# New Pod gets a different IP
kubectl describe pod nginx-deploy-def456 | grep IP
# IP: 10.244.2.3

This is why Services are critical: they provide a stable virtual IP and DNS name that front a dynamic set of Pod backends. Front-end Pods should talk to back-end Pods via a Service (backend-svc:8080), never by hardcoding Pod IPs. Source: CKA Day 9

Multi-Container Example

apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
  - name: sidecar
    image: busybox
    command: ['sh', '-c', 'echo Hello from sidecar && sleep 3600']

YAML Tips

  • Indentation matters — use spaces, never tabs
  • Validate before applying: kubectl apply --dry-run=client -f file.yaml
  • Explore fields: kubectl explain pod.spec

Production Note: You almost never deploy bare Pods in production. Pods are managed by higher-level controllers like Deployments and ReplicaSets, which provide self-healing, scaling, and rolling updates. Source: CKA Day 8

CKA Relevance

The CKA exam heavily tests both imperative speed and declarative reproducibility:

  • Create, debug, and modify Pods quickly under time pressure
  • Write YAML manifests from memory
  • Understand Pod networking and multi-container patterns
  • Know that Deployments manage ReplicaSets, which manage Pods

Practical Practice

Exam-style hands-on tasks for this topic. Complete each task before reviewing the solution. Time yourself — CKA tasks average 5–7 minutes.

Task 1: Create a Basic Nginx Pod You are asked to create a Pod named nginx running image nginx:alpine and exposing port 80. Requirements: Use an imperative command; verify the Pod is Running. Verification: kubectl get pod nginx Solution:

kubectl run nginx --image=nginx:alpine --port=80

Task 2: Multi-Container Pod with Shared Volume You are asked to create a Pod named web-log with two containers: an nginx container and a busybox sidecar. Both must share an emptyDir volume mounted at /var/log/nginx so the sidecar can read nginx logs. Requirements: Use --dry-run=client -o yaml, edit the manifest to add the second container and volume, then apply. Verification: kubectl get pod web-log and kubectl exec web-log -c sidecar -- ls /var/log/nginx Solution:

kubectl run web-log --image=nginx --dry-run=client -o yaml > web-log.yaml
# Edit web-log.yaml to add the busybox sidecar and an emptyDir volume at /var/log/nginx
kubectl apply -f web-log.yaml

Task 3: Fix a Broken Pod Image A Pod named broken-app was created with image nginx:999 and is stuck in ImagePullBackOff. Fix it to use nginx:latest. Requirements: Edit the live object directly; do not delete and recreate. Verification: kubectl get pod broken-app shows Running. Solution:

kubectl set image pod/broken-app broken-app=nginx:latest
# or: kubectl edit pod broken-app

Task 4: Export, Edit, and Re-apply a Pod You are asked to export the running Pod nginx to YAML, change its image to nginx:1.25, and re-apply the manifest. Requirements: Use kubectl get with -o yaml, redirect to a file, edit the image field, then apply. Verification: kubectl get pod nginx -o jsonpath='{.spec.containers[0].image}' Solution:

kubectl get pod nginx -o yaml > nginx-updated.yaml
# Edit the image field to nginx:1.25
kubectl apply -f nginx-updated.yaml --force

Tags: kubernetes pod workload yaml cka devops containers