Pods

Difficulty: Beginner

Question

What is a Pod in Kubernetes, and why does Kubernetes schedule Pods instead of individual containers?

Answer

A Pod is the smallest deployable unit in Kubernetes: a group of one or more containers that are always scheduled onto the same node and share a network namespace, an IP address and optionally storage volumes. Kubernetes schedules Pods rather than raw containers so that tightly coupled helpers (like a log shipper or proxy) can live next to the main app and behave like processes on one machine.

What containers in a Pod share

  • Network: one IP and one port space. Containers reach each other over localhost, so two containers in the same Pod cannot both bind port 8080.
  • Volumes: any volume declared in the Pod spec, such as an emptyDir, can be mounted by several containers to exchange files.
  • Lifecycle and placement: all containers are scheduled together, on the same node, and the Pod is the unit that gets restarted, evicted or deleted.
  • Not shared by default: filesystems (each container has its own image) and the process namespace, unless you set shareProcessNamespace: true.

Under the hood the kubelet creates a tiny "pause" (sandbox) container that holds the network namespace, and the app containers join it.

Why not just run containers directly

A container is meant to run one process. Real services often need helpers that must share the same network and disk: an Envoy proxy for a service mesh, a Fluent Bit sidecar shipping logs, or a process that refreshes TLS certificates. If these were separate scheduling units, they could land on different nodes and could not talk over localhost. The Pod gives Kubernetes a single "logical host" to schedule, monitor and scale. It also lets Kubernetes stay runtime-agnostic: the Pod spec is the same whether the node uses containerd or CRI-O.

Common Pod patterns

PatternExamplePurpose
Single containerA Node.js APIThe most common case, by far
SidecarEnvoy, Fluent BitAdds networking or logging next to the app
Init containerWait for DB, run migrationsRuns to completion before app containers start
Ambassador / adapterLocal proxy to RedisSimplifies how the app reaches external systems

Since Kubernetes v1.29 (beta, on by default) and GA in v1.33, native sidecars are declared as init containers with restartPolicy: Always. They start before the app and keep running, which fixes old problems such as Jobs never finishing because a sidecar kept running.

Gotchas worth knowing

  • Pods are ephemeral. If one dies, its replacement gets a new name and a new IP. Never hard-code Pod IPs; use a Service.
  • You almost never create bare Pods in production. Use a Deployment, StatefulSet, Job or DaemonSet so a controller recreates them on failure. A bare Pod on a node that dies is simply gone.
  • Scaling is per Pod: if you put your API and your database in one Pod, scaling the API to 10 replicas also creates 10 databases. Only group containers that must scale together.
Inside a Pod. Containers in a Pod sit on one shared network namespace and can share volumes.
  1. App container: Your main process, for example a Spring Boot API on port 8080.
  2. Sidecar container: Optional helper such as a log shipper or proxy.
  3. Shared volumes: emptyDir or PVC mounts visible to chosen containers.
  4. Pause container network namespace: Holds the single Pod IP and port space.
  5. Node (kubelet + runtime): All containers in the Pod run on this one node.

Code examples

Pod with an app and a native sidecar sharing a volume

apiVersion: v1
kind: Pod
metadata:
  name: orders-api
  labels:
    app: orders
spec:
  initContainers:
    - name: log-shipper            # native sidecar (v1.29+)
      image: fluent/fluent-bit:3.1
      restartPolicy: Always        # keeps running alongside the app
      volumeMounts:
        - name: logs
          mountPath: /var/log/app
  containers:
    - name: api
      image: ghcr.io/acme/orders-api:1.4.2
      ports:
        - containerPort: 8080
      volumeMounts:
        - name: logs
          mountPath: /var/log/app  # app writes logs here
  volumes:
    - name: logs
      emptyDir: {}

Both containers mount the same emptyDir, so the sidecar can read the files the API writes. They also share the Pod IP, so the sidecar could reach the API at localhost:8080.

Key points

  • A Pod is one or more containers sharing a network namespace, IP and volumes, always on one node.
  • Containers in the same Pod talk over localhost and cannot reuse the same port.
  • Pods are disposable; a recreated Pod gets a new IP, so use Services for stable access.
  • Run Pods through controllers (Deployment, StatefulSet, Job), not as bare Pods.
  • Native sidecars are init containers with restartPolicy: Always, GA since v1.33.

Common follow-up questions

  • What is the pause container and why does it exist?
  • How do init containers differ from sidecar containers?
  • Would you put an app and its database in the same Pod? Why not?
  • What happens to a bare Pod if its node fails?

Interview tips

  • Lead with the shared network namespace; it is the real reason Pods exist and it explains the localhost behaviour.
  • Give a concrete sidecar example like a service mesh proxy or log shipper to show production awareness.
  • Point out that the scaling unit is the Pod, which is why unrelated components should never share one.

Concepts covered

Pod, Sidecar Container, Init Container, Shared Network Namespace, Ephemeral IP

More Kubernetes & Orchestration questions