Room 07
MULTI-CONTAINER PODS
The Assembly Line
- Some pods need multiple containers working together - sidecars for logging, init containers for setup, and ambassadors for proxying.
- Build a multi-container pod and extract data from the sidecar.
📜 Mission Briefing
- Study the
multi-pod.yamlfile in this room. It defines a pod with: - An init container that writes a secret to a shared volume
- A main container running nginx
- A sidecar container that reads logs
- Apply the manifest:
kubectl apply -f multi-pod.yaml. - Wait for the pod to be Running.
- The init container wrote a file
/shared/password.txtto a sharedemptyDirvolume. - Exec into the main container and read
/shared/password.txt. - The content is your password.
Key Commands
| Command | Purpose |
|---|---|
kubectl apply -f FILE |
Apply a manifest |
kubectl get pod NAME |
Check pod status |
kubectl describe pod NAME |
See init container status |
kubectl logs NAME -c CONTAINER |
Logs from specific container |
kubectl exec -it NAME -c CONTAINER -- CMD |
Exec into specific container |
Multi-Container Pod Patterns
# Init Container: Runs BEFORE main containers, must complete successfully
apiVersion: v1
kind: Pod
metadata:
name: init-demo
spec:
initContainers:
- name: init-setup
image: busybox
command: ['sh', '-c', 'echo "ready" > /work-dir/status']
volumeMounts:
- name: shared
mountPath: /work-dir
containers:
- name: main
image: nginx:alpine
volumeMounts:
- name: shared
mountPath: /usr/share/nginx/html
volumes:
- name: shared
emptyDir: {}
# Sidecar Pattern: Helper container runs alongside main
apiVersion: v1
kind: Pod
metadata:
name: sidecar-demo
spec:
containers:
- name: main
image: nginx:alpine
volumeMounts:
- name: logs
mountPath: /var/log/nginx
- name: log-shipper
image: busybox
command: ['sh', '-c', 'tail -f /var/log/nginx/access.log']
volumeMounts:
- name: logs
mountPath: /var/log/nginx
volumes:
- name: logs
emptyDir: {}
# Common patterns:
# 1. Sidecar: logging, monitoring, proxying alongside main
# 2. Ambassador: proxy to external services
# 3. Adapter: transform output of main container
# Check init container status
kubectl describe pod init-demo | grep -A 5 "Init Containers"
# View logs from specific container
kubectl logs sidecar-demo -c log-shipper
# Exec into specific container
kubectl exec -it sidecar-demo -c main -- /bin/sh
Hints
Hint 1
Apply the manifest and wait for it to be ready:
Hint 2
Exec into the main container and read the shared file:
Hint 3
The password is sidecar77.