Pods

A Pod is the smallest unit you can deploy and manage in Kubernetes. It holds one or more containers, storage, a network identity, and instructions on how the containers should run.

Key Characteristics of a Pod

  • Basic Unit of Deployment: Kubernetes does not run containers directly. It always runs them inside Pods.
  • Multiple Containers (Optional): A Pod can run one container or several that work closely together (like a main app and a helper).
  • Shared Resources: Containers in the same Pod share the same storage and network. They can talk to each other using localhost.
  • Ephemeral: Pods are temporary. If a Pod fails, Kubernetes creates a new one instead of fixing the old one.

Components of a Pod

  • Containers: One or more app containers running inside the Pod.
  • Storage Volumes: Shared storage that all containers in the Pod can use.
  • Networking: A Pod gets its own IP. Containers inside the Pod use localhost to talk to each other.
  • PodSpec: This defines what the Pod should run, how much CPU or memory it needs, and how to check its health.

Sample Pod YAML

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: web
spec:
  containers:
  - name: nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80

YAML Field Descriptions

  • apiVersion: Version of the Kubernetes API
  • kind: Type of object being created (Pod)
  • metadata: Name and labels for the Pod
  • spec: Defines what containers run and how
  • containers: List of container definitions within the Pod

Common Pod Commands

  • kubectl run nginx --image=nginx – Create a Pod using imperative command
  • kubectl get pods – List all Pods
  • kubectl describe pod nginx-pod – View detailed Pod info
  • kubectl delete pod nginx-pod – Delete a Pod
  • kubectl apply -f pod.yaml – Create a Pod from YAML file

Pod Networking

  • Each Pod gets a unique IP address
  • Containers inside a Pod use localhost to communicate
  • Pods communicate with other Pods via the Kubernetes network

Pod Lifecycle

  • Pending: Pod is created but not running yet
  • Running: Containers are active
  • Succeeded: Containers exited successfully
  • Failed: One or more containers failed
  • Unknown: Kubernetes can’t get Pod status

Why Use Pods Instead of Just Containers?

  • Shared Resources: Share storage and networking
  • Sidecar Containers: Use helper containers like loggers or proxies
  • Kubernetes Integration: Pods are the unit Kubernetes schedules, scales, and monitors

Pod Use Cases

  • Single-Container Pods: Most Pods run a single container
  • Multi-Container Pods: Use when tightly coupled containers must run together, like:
    • A web server with a logging sidecar
    • A database with a backup sidecar

Think of a Pod as a shared space where tightly connected containers live and operate together.