Skip to content

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

  1. Study the multi-pod.yaml file in this room. It defines a pod with:
  2. An init container that writes a secret to a shared volume
  3. A main container running nginx
  4. A sidecar container that reads logs
  5. Apply the manifest: kubectl apply -f multi-pod.yaml.
  6. Wait for the pod to be Running.
  7. The init container wrote a file /shared/password.txt to a shared emptyDir volume.
  8. Exec into the main container and read /shared/password.txt.
  9. 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:

kubectl apply -f multi-pod.yaml
kubectl get pod multi-pod --watch

Hint 2

Exec into the main container and read the shared file:

kubectl exec -it multi-pod -c main -- cat /shared/password.txt

Hint 3

The password is sidecar77.


🔓 Unlock Room 08

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_08/README             \
        -out ../room_08/README.txt        \
        -pass pass:PASSWORD
cat ../room_08/README.txt