By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
A Hyper-Practical Study Guide for Docker & Kubernetes
A Pod is the smallest deployable unit in Kubernetes—think of it as a "logical host" for one or more containers. While most tutorials start with single-container Pods, multi-container Pods are where Kubernetes shines in production.
If you ignore multi-container patterns:❌ Your app becomes a monolith inside a single container (harder to debug, scale, or update).❌ You reinvent the wheel (e.g., writing custom log shippers instead of using Fluent Bit as a sidecar).❌ Your Pods violate the Single Responsibility Principle, making them brittle and hard to maintain.
Superpower you gain:✅ Decouple concerns (e.g., logging, monitoring, networking) from your main app.✅ Reuse existing tools (e.g., Envoy for traffic management, Prometheus Node Exporter for metrics).✅ Simplify debugging (e.g., kubectl logs -c sidecar lets you inspect logs without touching the main app).
kubectl logs -c sidecar
emptyDir
PersistentVolume
localhost
initContainer
git clone
initContainers
configMap
secret
kubectl
kubectl get pods
kubectl describe pod <name>
kubectl logs <pod> -c <container>
kubectl exec -it <pod> -c <container> -- sh
Scenario: You have a legacy app that writes logs to /var/log/app.log. You need to ship these logs to Elasticsearch using Fluent Bit.
/var/log/app.log
The main app and sidecar need to share the log file.
# pod-sidecar.yaml apiVersion: v1 kind: Pod metadata: name: app-with-sidecar spec: volumes: - name: shared-logs emptyDir: {}
This container writes logs to the shared volume.
containers: - name: main-app image: busybox command: ["/bin/sh", "-c"] args: - while true; do echo "$(date) - Log entry" >> /var/log/app.log; sleep 5; done volumeMounts: - name: shared-logs mountPath: /var/log
This container tails the log file and forwards it to Elasticsearch (simplified for demo).
- name: fluent-bit image: fluent/fluent-bit volumeMounts: - name: shared-logs mountPath: /var/log env: - name: FLUENT_ELASTICSEARCH_HOST value: "elasticsearch" - name: FLUENT_ELASTICSEARCH_PORT value: "9200"
kubectl apply -f pod-sidecar.yaml
# Check logs from the sidecar kubectl logs app-with-sidecar -c fluent-bit # Expected output: Fluent Bit startup logs (no errors)
kubectl exec -it app-with-sidecar -c main-app -- sh cat /var/log/app.log # Expected output: Timestamped log entries
requests
limits
sidecar-fluent-bit
fluentbit_input_records_total
[sidecar] Fluent Bit started
emptyDir.sizeLimit
Init:CrashLoopBackOff
kubectl describe pod
Bind: address already in use
❌ Adapter (wrong use case).
"How do containers in a Pod communicate?"
❌ Service DNS (only for inter-Pod communication).
"What’s the difference between a sidecar and an initContainer?"
Challenge:Deploy a Pod with: 1. A main app that writes metrics to /metrics in JSON format.2. An adapter sidecar that converts the JSON to Prometheus format and exposes it on :9090/metrics.
/metrics
:9090/metrics
Solution:
apiVersion: v1 kind: Pod metadata: name: metrics-adapter spec: containers: - name: main-app image: busybox command: ["/bin/sh", "-c"] args: - while true; do echo '{"requests": 100, "errors": 2}' > /metrics/raw.json; sleep 5; done volumeMounts: - name: metrics mountPath: /metrics - name: adapter image: prom/prometheus command: ["/bin/sh", "-c"] args: - while true; do jq -r '.requests as $r | .errors as $e | "# HELP http_requests_total Total HTTP requests\n# TYPE http_requests_total counter\nhttp_requests_total $r\n# HELP http_errors_total Total HTTP errors\n# TYPE http_errors_total counter\nhttp_errors_total $e"' /metrics/raw.json > /metrics/prometheus.txt; sleep 5; done volumeMounts: - name: metrics mountPath: /metrics ports: - containerPort: 9090 volumes: - name: metrics emptyDir: {}
Why It Works:- The main app writes JSON to a shared volume.- The adapter sidecar converts it to Prometheus format and exposes it on :9090.
:9090
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.