What You Will Learn
Intermediate
- Three multi-container patterns
- When to use each
- How containers in a Pod communicate
Three Patterns
| Pattern | What it does | Example |
|---|---|---|
| Sidecar | Enhances the main container | Log collector, monitoring agent |
| Adapter | Transforms output | Log formatter, metrics converter |
| Ambassador | Acts as a proxy | Redis proxy, service mesh |
sidecar.yamlyaml
apiVersion: v1
kind: Pod
metadata:
name: web-with-logs
spec:
containers:
- name: nginx # Main container
image: nginx:alpine
- name: log-agent # Sidecar: collects logs
image: fluentd
volumeMounts:
- name: logs
mountPath: /var/log/nginx
volumes:
- name: logs
emptyDir: {} # Shared volume between containersContainers in a Pod share
All containers in a Pod share: the same network namespace (same IP), the same volumes, the same localhost. They can communicate via localhost.Practical Exercise
Create a Pod with 2 containers: nginx + busybox
The busybox sidecar writes to a shared volume
kubectl exec into the nginx container to read the file
Confirm they share the volume
Key Takeaways
- Sidecar: enhances main container (logging, monitoring).
- Adapter: transforms output (log formatting).
- Ambassador: acts as proxy (database connection pool).
- Containers in a Pod share networking and volumes.
- Use multi-container Pods only when containers are tightly coupled.
Comments
Comments
Post a Comment