Multi-Container Pods
What you'll learn: How to run multiple containers inside a single Pod and why they share certain resources.
Why Multiple Containers in One Pod?
So far you've seen Pods with a single container, but Kubernetes allows you to run multiple containers within the same Pod. This is useful when containers need to work together very closely—like a main application and a helper that processes logs or routes traffic.
Think of a Pod as a shared apartment. When multiple containers live in the same Pod, they share the same address (IP), the same storage volumes, and they can talk to each other via localhost. They're roommates, not neighbors.
What Resources Do They Share?
Containers in the same Pod share:
- Network namespace: Same IP address and port space. Container A can reach Container B at
localhost:port. - Storage volumes: Both can mount and access the same volumes.
- Lifecycle: They start together, stop together, and are scheduled on the same node.
Each container still has its own filesystem and can run different processes independently.
Common Patterns
Sidecar containers are the most common use case: a helper container that enhances the main container. Examples include:
- A logging agent that ships logs from the main app
- A proxy that handles authentication
- A monitoring agent that collects metrics
In your YAML, you simply list multiple containers under the containers array in the Pod spec.
apiVersion: v1
kind: Pod
metadata:
name: multi-app
spec:
containers:
- name: main-app
image: myapp:1.0
- name: log-shipper
image: fluentd:latest
Key Takeaway: Multi-container Pods let tightly-coupled containers share networking and storage, enabling powerful sidecar and helper patterns within a single schedulable unit.