A sidecar container is a secondary container that runs alongside the main application container within the same Pod. It extends or enhances the main application’s functionality without modifying the main application’s code.
Key properties:
Runs concurrently with the main container (not sequentially like init containers)
Shares the Pod’s network namespace and storage volumes
Has an independent lifecycle within the Pod — if it crashes, the main container may keep running (depending on restartPolicy)
Should be loosely coupled to the main app
Best practice: A sidecar should be able to start and stop independently without crashing the main app. Avoid hard dependencies where the main app fails if the sidecar is not yet ready. Source: CKA Day 11
Classic Sidecar Use Cases
1. Log Shipping
The sidecar reads application logs from a shared volume and forwards them to a centralized logging system (ELK, Loki, CloudWatch).
The sidecar handles TLS encryption/decryption so the main app can operate in plain HTTP. See TLS Fundamentals for how the handshake and certificate chain work.
Consumes CPU/memory that the main app needs; can trigger OOMKills
Tight coupling
Main app crashes if sidecar is unavailable; defeats the purpose of loose coupling
Stateful sidecar
Sidecars should be stateless or use external storage; losing a Pod means losing the sidecar’s state
Business logic in sidecar
Sidecars are infrastructure concerns; business logic belongs in the main app or a separate service
Sidecar as a substitute for a Service
If the auxiliary function could be a standalone microservice, it probably should be
CKA Exam Relevance
You may be asked to write a Pod spec with a sidecar that shares a volume with the main app
Understand that sidecars appear in the same containers list as the main app
Know how to get logs from a specific sidecar container: kubectl logs <pod> -c <sidecar>
Be able to explain why a sidecar is preferred over an init container for long-running auxiliary tasks
Practical Practice
Exam-style hands-on tasks for this topic. Complete each task before reviewing the solution. Time yourself — CKA tasks average 5–7 minutes.
Task 1: Nginx with Fluent-Bit Log Sidecar
You are asked to deploy a Pod named web-logger where an nginx container serves content and a fluent-bit sidecar forwards logs from a shared volume to stdout.
Requirements: Use an emptyDir volume at /var/log/nginx. The fluent-bit sidecar must tail the access log.
Verification:kubectl logs web-logger -c fluent-bit shows nginx access lines.
Solution:
Task 2: Add a Health-Check Sidecar to a Deployment
You are asked to add a sidecar container to an existing Deployment that periodically curls localhost:80/healthz and logs the HTTP status.
Requirements: The sidecar uses busybox and runs an infinite loop with sleep 10 between curls.
Verification:kubectl logs <pod> -c health-checker shows curl output.
Solution:
kubectl get deployment <name> -o yaml > deploy.yaml# Add a second container named health-checker with image busybox# command: ['sh', '-c', 'while true; do curl -s -o /dev/null -w "%{http_code}" localhost:80/healthz; echo; sleep 10; done']kubectl apply -f deploy.yaml
Task 3: TLS Termination Sidecar
You are asked to create a Pod tls-app where the main app listens on HTTP port 8080 and an nginx:alpine sidecar terminates TLS on port 443, proxying to localhost:8080.
Requirements: Mount a TLS certificate Secret at /etc/nginx/ssl. Configure nginx as a reverse proxy.
Verification:kubectl get pod tls-app is Running; kubectl exec tls-app -c proxy -- nginx -t passes.
Solution: