Skip to content

Kubernetes Pods Explained — The Atomic Unit of K8s

DodaTech 2 min read

In this tutorial, you'll learn about Kubernetes Pods Explained. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

What You'll Learn

Understand Kubernetes pods — the smallest deployable unit, how containers run inside pods, pod lifecycle, health probes, and common patterns.

Why It Matters

Everything in Kubernetes runs in a pod. Mastering pods is essential to understanding deployments, jobs, daemonsets, and the entire K8s ecosystem.

Real-World Use

Running a web server with a sidecar that syncs files, an app with a logging agent, or a batch job that processes data and exits.

What is a Pod?

A pod is one or more containers that share:

  • Network namespace (same IP, same port space)
  • Storage volumes
  • Lifecycle
  • Node assignment
Pod "web"
┌─────────────────────────────────┐
│ Container: nginx (port 80)     │
│ Container: file-sync (sidecar) │
│ Volume: shared-data            │
│ IP: 10.1.0.5                   │
└─────────────────────────────────┘

Single Container Pod

apiVersion: v1
kind: Pod
metadata:
  name: single-pod
  labels:
    app: my-app
spec:
  containers:
    - name: app
      image: nginx:alpine
      ports:
        - containerPort: 80
      resources:
        requests:
          memory: "64Mi"
          cpu: "100m"
        limits:
          memory: "128Mi"
          cpu: "200m"

Multi-Container Pod

Containers in the same pod can communicate via localhost:

apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  volumes:
    - name: shared-data
      emptyDir: {}

  containers:
    - name: app
      image: nginx:alpine
      volumeMounts:
        - name: shared-data
          mountPath: /usr/share/nginx/html

    - name: content-fetcher
      image: alpine
      command: ["/bin/sh", "-c"]
      args:
        - while true; do
            wget -q -O /data/index.html https://example.com;
            sleep 3600;
          done
      volumeMounts:
        - name: shared-data
          mountPath: /data

Pod Lifecycle

Pending → ContainerCreating → Running → Succeeded/Failed
                                         ↓
                                    CrashLoopBackOff
  • Pending: Pod accepted but not yet scheduled
  • ContainerCreating: Image pulling, container starting
  • Running: All containers running
  • Succeeded: All containers exited with code 0
  • Failed: At least one container exited with non-zero
  • CrashLoopBackOff: Container keeps crashing

Init Containers

Run before app containers start:

spec:
  initContainers:
    - name: init-db
      image: alpine
      command:
        - sh
        - -c
        - "until nc -z db-service 5432; do sleep 1; done"

  containers:
    - name: app
      image: my-app

Health Probes

spec:
  containers:
    - name: app
      livenessProbe:      # Is the container alive?
        httpGet:
          path: /health
          port: 3000
        initialDelaySeconds: 5
        periodSeconds: 10

      readinessProbe:     # Is it ready to serve traffic?
        httpGet:
          path: /ready
          port: 3000
        initialDelaySeconds: 3
        periodSeconds: 5

      startupProbe:       # Has it finished starting?
        httpGet:
          path: /startup
          port: 3000
        initialDelaySeconds: 1
        periodSeconds: 2
        failureThreshold: 30

Common Pod Patterns

Pattern Description
Sidecar Helper container alongside the main app (logging, proxy)
Ambassador Proxy container that handles external connections
Adapter Transforms output (e.g., log format converter)
Init Runs setup tasks before main containers start

Debugging Pods

# View pod status
kubectl get pods
kubectl describe pod web-pod

# View logs
kubectl logs web-pod
kubectl logs -l app=web        # All pods with label
kubectl logs web-pod -c sidecar  # Specific container

# Exec into pod
kubectl exec -it web-pod -- sh
kubectl exec -it web-pod -c sidecar -- sh

# Port forward
kubectl port-forward pod/web-pod 8080:80

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro