IT 3300 : Virtualization

Kubernetes — Pods

What is a pod?

  • The smallest deployable unit in Kubernetes
  • One or more containers that are tightly coupled
  • Containers in a pod share:
    • a network namespace (same IP, reach each other on localhost)
    • storage volumes

Usually one container per pod

  • Most pods = a single app container
  • Multiple containers only when tightly coupled (e.g. a sidecar
    that ships logs or serves as a proxy)
  • If they don't need to share resources, use separate pods

A pod, imperatively

    kubectl run web --image=nginx
    kubectl get pods
    kubectl describe pod web
  • Quick for experiments — but real work uses YAML (next deck)

A pod, declaratively

apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  containers:
    - name: web
      image: nginx:1.27
      ports:
        - containerPort: 80

    kubectl apply -f pod.yaml

Inspecting pods

  • kubectl get pods -o wide — which node, which IP
  • kubectl describe pod web — events, status, why it's stuck
  • kubectl logs web — the container's output
  • kubectl exec -it web -- bash — a shell inside

Pods are disposable

  • Each pod gets its own IP — but pods come and go
  • When a node dies, its pods are not rescheduled; they're replaced
  • A replacement is a new pod (new UID, maybe new IP)
  • Lesson: never depend on a specific pod or its IP

So who replaces them?

  • You rarely create bare pods in production
  • A controller (Deployment) watches desired vs. actual and recreates
    pods to keep the count right — that's next

Lab goals

  • Create a pod from YAML and inspect it
  • Delete the bare pod; confirm nothing brings it back
  • Note why that's a problem worth solving