K8s by Example: Sidecar Pattern
| The sidecar pattern deploys helper containers alongside your main application container in the same Pod. Sidecars share the Pod’s network namespace (localhost) and can share volumes. Use for: logging, monitoring, proxying, configuration sync, and security. |
| sidecar-logging.yaml | |
| A logging sidecar reads application logs from a shared volume and ships them to a centralized logging system. The main app writes logs to a file; the sidecar streams them. | |
| The | |
| sidecar-git-sync.yaml | |
| A git-sync sidecar keeps configuration files updated by periodically pulling from a Git repository. The main app reads config from a shared volume that the sidecar keeps synchronized. | |
| sidecar-https.yaml | |
| An HTTPS termination sidecar handles TLS, allowing legacy apps to serve HTTP on localhost. Nginx terminates SSL on port 443 and proxies to the app on localhost:8080. Both containers share the network namespace. | |
| nginx-ssl-config.yaml | |
| The nginx ConfigMap configures SSL termination. It listens on 443, terminates TLS, and proxies requests to the app container on localhost:8080 (shared network namespace). | |
| sidecar-monitoring.yaml | |
| A monitoring sidecar collects metrics from the main app and exposes them in Prometheus format. The sidecar queries the app’s internal metrics endpoint and transforms them to a standard format. | |
| terminal | |
| Sidecar containers start and stop with the Pod. Check both containers are Running. Shared volumes appear in each container’s mounts. Logs from each container are accessed separately. | |