Build · shipped

30 Days of Kubernetes (CKAD) — Day 02: Multi-Container Pods & The Sidecar Pattern

Day 02 of the 30-day CKAD hands-on series: understanding Sidecar, Adapter, and Ambassador patterns and sharing emptyDir volumes inside a Pod.

In Kubernetes, a Pod is the smallest deployable unit. While most Pods run a single container, CKAD frequently tests multi-container Pods where two or more containers share lifecycle, network namespace (localhost), and storage volumes.


1. The Three Multi-Container Patterns

  1. Sidecar: Enhances or extends the main container (e.g., log shippers like Fluentbit tailing a shared log file).
  2. Adapter: Standardizes or transforms the main container's output (e.g., converting custom app metrics into Prometheus format).
  3. Ambassador: Proxies network connections for the main container (e.g., local Redis/DB proxy on localhost).

2. How Containers Share Files (emptyDir)

An emptyDir volume is created when a Pod is assigned to a Node and exists as long as that Pod runs on that Node. Both containers mount the same volume name:

volumes:
  - name: shared-logs
    emptyDir: {}

3. Hands-On Lab: Day 02

In labs/k8s-30-days/day-02/:

  1. Create namespace ckad-day02.
  2. Deploy logger-pod with:
    • Container app (busybox:1.36) writing timestamps to /var/log/app/app.log.
    • Container sidecar (busybox:1.36) tailing /var/log/app/app.log.
    • Both sharing an emptyDir volume named shared-logs.
  3. Inspect the sidecar output:
    k logs logger-pod -n ckad-day02 -c sidecar
    
  4. Verify with ./labs/k8s-30-days/day-02/verify.sh.

Search DivineForge