Multi-Container Pods Overview
The most common scenario for multi-container pods is having a main container with one or more helper processes that assist the main application.
Key Benefits:
- Containers share the same network namespace
- Containers can communicate via localhost
- Containers share the same storage volumes
- Tighter coupling than separate pods
Common Multi-Container Patterns
Sidecar Pattern
A sidecar container extends or enhances the main container without modifying it. Common use cases include logging, monitoring, or syncing data.
Use Cases:
- Log collection and shipping
- File synchronization
- Monitoring agents
- Configuration reloaders
Note: The sidecar container typically has the same lifecycle as the main application container.
Adapter Pattern
The adapter container transforms the output of the main container to a standardized format that can be consumed by other services.
Use Cases:
- Normalizing monitoring data
- Formatting logs consistently
- Converting data formats
- Protocol translation
Note: The adapter helps standardize output from diverse applications.
Ambassador Pattern
The ambassador container acts as a proxy or broker for the main container, handling connections to external services.
Use Cases:
- Database connection proxying
- Service discovery abstraction
- Load balancing
- Circuit breaker implementation
Note: The ambassador simplifies connection logic for the main application.
Multi-Container Pod Definition
apiVersion: v1
kind: Pod
metadata:
name: two-containers
spec:
restartPolicy: Always
containers:
- name: mynginx
image: nginx
ports:
- containerPort: 80
- name: mybox
image: busybox
ports:
- containerPort: 81
command:
- sleep
- "3600"
Container Details
Container #1: mynginx
- Image: nginx
- Port: 80
- Primary web server
Container #2: mybox
- Image: busybox
- Port: 81
- Command: sleep 3600
- Helper/utility container
kubectl Pod Cheat Sheet
Create a Pod
Creates a pod from a YAML definition file.
Exec into a Pod
Opens an interactive shell in a specific container.
Get Container Logs
Retrieves logs from a specific container in a pod.