CKA Day 11 — Multi Container Pod Kubernetes: Sidecar vs Init Container
Day 11/40 of the Certified Kubernetes Administrator (CKA) Full Course by Tech Tutorials with Piyush. This video explores multi-container Pods in Kubernetes — covering environment variables, init containers, sidecar patterns, commands/arguments in Pod YAML, live demos, and troubleshooting.
Overview
While Day 7 introduced the Pod as the smallest deployable unit, Day 11 goes deeper into the multi-container patterns that make Pods more than just single-container wrappers. The video covers:
- How to inject configuration via environment variables
- The three container roles inside a Pod: main app, sidecar, and init
- How init containers run to completion before the main app starts
- How sidecar containers run alongside the main app to provide auxiliary services
- How commands and arguments override container defaults
- Live demo and troubleshooting common multi-container Pod failures
Source Details
- Channel: Tech Tutorials with Piyush
- Playlist: 40 Days of Kubernetes (CKA Full Course)
- Companion Repository: piyushsachdeva/CKA-2024
- Challenge:
#40daysofKubernetes
Key Takeaways
1. Environment Variables in Kubernetes
Environment variables are the simplest way to inject configuration into containers without baking secrets into images.
Inline value:
spec:
containers:
- name: my-app
image: nginx
env:
- name: ENVIRONMENT
value: "production"From ConfigMap:
env:
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app-config
key: log_levelFrom Secret:
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: passwordExam Tip: Know the difference between
value(literal),configMapKeyRef(non-sensitive config), andsecretKeyRef(sensitive data). Secrets are base64-encoded at rest but not encrypted by default. Source: CKA Day 11
2. Multi-Container Pods
A Pod can run multiple containers that share:
- Network namespace (same
localhost, same IP) - Storage volumes (shared filesystems via
emptyDir,hostPath, or persistent volumes) - IPC namespace (optional inter-process communication)
Common multi-container patterns:
| Pattern | Purpose | Example |
|---|---|---|
| Sidecar | Auxiliary service alongside main app | Logging agent, monitoring exporter, reverse proxy |
| Init | Pre-start setup/validation | Database migration, config generation, permission fix |
| Adapter | Transform output format | Metrics normalizer, log parser |
| Ambassador | Proxy external connections | Service mesh proxy, database connection pooler |
CKA Trap: Init containers run serially and must complete successfully before any regular container starts. If an init container fails, the Pod is stuck in
Init:ErrororInit:CrashLoopBackOff. Source: CKA Day 11
3. Init Containers
Init containers are defined under spec.initContainers and execute in order before the main containers start.
apiVersion: v1
kind: Pod
metadata:
name: init-demo
spec:
initContainers:
- name: wait-for-service
image: busybox:1.36
command: ['sh', '-c', 'until wget -qO- http://backend:8080/health; do sleep 2; done']
- name: init-migrate
image: migrate/migrate
command: ["migrate", "-path", "/migrations", "-database", "postgres://db:5432/app?sslmode=disable", "up"]
containers:
- name: app
image: my-app:1.0
ports:
- containerPort: 8080Key behaviors:
- Init containers run sequentially —
wait-for-servicemust finish beforeinit-migratestarts - If any init container fails, Kubernetes restarts the Pod according to
restartPolicy - Init containers do not support
livenessProbe,readinessProbe, orstartupProbe - Resource limits for init containers affect Pod scheduling (highest value wins)
Troubleshooting init containers:
kubectl describe pod init-demo # Check Init Container States
kubectl logs init-demo -c wait-for-service # Logs from a specific init container
kubectl get pod init-demo -o yaml # Full spec and status4. Sidecar Containers
Sidecars run concurrently with the main application container(s) inside the same Pod.
apiVersion: v1
kind: Pod
metadata:
name: sidecar-demo
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
- name: log-shipper
image: fluentd
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
volumes:
- name: shared-logs
emptyDir: {}Sidecar use cases:
- Log shipping: Read application logs from a shared volume and forward to centralized store
- Monitoring: Expose Prometheus metrics or run a health-check proxy
- TLS termination: Terminate TLS before traffic reaches the main app
- Configuration reload: Watch for ConfigMap/Secret changes and signal the main app to reload
Best practice: Sidecars should be lightweight. A heavy sidecar can starve the main app of CPU/memory and trigger OOMKills. Always set resource requests/limits for both containers. Source: CKA Day 11
5. Commands and Arguments in Pod YAML
Containers have a default command and args defined in their image (Dockerfile ENTRYPOINT and CMD). Kubernetes allows overriding both.
| Kubernetes Field | Docker Equivalent | Purpose |
|---|---|---|
command | ENTRYPOINT | The executable to run |
args | CMD | Arguments passed to the executable |
Override example:
spec:
containers:
- name: sleeper
image: busybox
command: ["sleep"] # Overrides ENTRYPOINT
args: ["3600"] # Overrides CMDUsing shell form:
spec:
containers:
- name: init-db
image: postgres:15
command: ["/bin/sh"]
args: ["-c", "psql -U admin -d mydb -f /schema.sql"]Exam Tip:
commandandargsare not combined with the image defaults — they fully replace them. To append to the image default, you must know what the default is and reproduce it. Source: CKA Day 11
6. Live Demo & Troubleshooting
The video demonstrates creating a multi-container Pod, observing init container execution, verifying shared volumes, and debugging common failures:
| Symptom | Cause | Fix |
|---|---|---|
Pod stuck in Init:0/1 | Init container hasn’t finished yet | Check logs: kubectl logs <pod> -c <init-container> |
Pod stuck in Init:Error | Init container exited non-zero | Fix the command/script; ensure dependencies are reachable |
CrashLoopBackOff | Main container exits repeatedly | Check kubectl describe pod, kubectl logs |
| Sidecar not sharing data | Volume not mounted at same path in both containers | Verify volumeMounts.mountPath alignment |
| OOMKilled | Container exceeded memory limit | Increase resources.limits.memory or optimize app |
7. Why This Matters for CKA
- The CKA exam tests Pod spec fluency — you must write multi-container Pod YAML from memory
- Init containers appear in troubleshooting scenarios (Pods stuck pending)
- Sidecars appear in networking and storage questions (shared volumes, proxy patterns)
- Environment variables are tested in configuration and security contexts
- Command/args override is tested when customizing standard images
See Also
Wiki Concepts
- Multi-Container Pods — comprehensive guide to multi-container patterns, YAML anatomy, and exam patterns
- Init Containers — deep dive into initialization workflows, ordering, and troubleshooting
- Sidecar Pattern — architecture, use cases, and anti-patterns for sidecar containers
- Kubernetes Environment Variables — ConfigMap, Secret, and literal injection patterns
- Pod Commands and Arguments — overriding ENTRYPOINT/CMD and shell execution
- Pod Fundamentals — foundational Pod concepts from Day 7
- Deployment, ReplicaSet & Replication Controller — workload controllers that manage multi-container Pods
- Kubernetes Namespaces — isolating multi-container workloads
- Kubernetes Architecture — how kubelet orchestrates containers within a Pod
- CKA Certification — exam domains where multi-container Pods appear
- CKA Study Roadmap — Day 11 in the 40-day plan
Related Sources
- CKA Day 7 — Pod Explained — prerequisite: single-container Pod basics
- CKA Day 8 — Deployments, ReplicaSets & Replication Controllers — workload controllers that deploy multi-container Pods
- CKA Day 9 — Kubernetes Services Explained — exposing multi-container Pods via Services
- CKA Day 10 — Kubernetes Namespace Explained — isolating multi-container workloads
Creator / Entity
- Tech Tutorials with Piyush — CKA 40-day challenge series
Ingested: 2026-06-03