Q&A-3Decide whether two processes belong in one Pod.
Answer
The rule
Put two processes in one Pod only when they must share a network namespace, a volume, or a lifecycle. If they can talk over a Service and be deployed, scaled and owned separately, they are two workloads.
What a Pod actually shares
Containers in a Pod share a network namespace (one IP, one port space) plus IPC, any volumes you mount, and the ServiceAccount token. shareProcessNamespace: true adds a shared PID namespace. restartPolicy is a Pod-level field, not per container. That sharing is the reason to co-schedule, and it is also the risk.
Why shared fate bites
Readiness is the sharpest case. The kubelet ANDs every container's readiness into the Pod's Ready condition, and the endpoints controller gates Service endpoints on that condition. A sidecar whose readiness probe fails takes the healthy app container out of rotation. Liveness is different: a failing liveness probe restarts only its own container.
Resources are summed. The Pod's QoS class comes from the requests and limits of all its containers, so one sidecar with no requests drops the Pod from Guaranteed to Burstable and moves it earlier in node eviction order. Ports collide because the netns is shared. Identity is shared because every container mounts the same token by default.
Termination is the one place Kubernetes now helps: a native sidecar. An initContainers entry with restartPolicy: Always, beta since 1.29. Starts before the app containers and is terminated after them. Ordinary containers all receive SIGTERM in parallel, so a log shipper can die before it flushes.
| Coupling | Mechanism | Symptom |
|---|---|---|
| Network | one netns, one port space | sidecar binds 8080, app already holds it, CrashLoopBackOff |
| Readiness | Pod Ready = AND of container readiness | app healthy, 0 endpoints, 503s |
| Resources | QoS class from summed requests/limits | sidecar with no requests → Burstable → evicted first |
| Identity | one ServiceAccount token in every container | sidecar inherits the app's RBAC |
| Termination | parallel SIGTERM unless native sidecar | shipper killed mid-flush, logs lost |
Trace: a sidecar readiness failure
- The sidecar's
/readyprobe fails three times; the kubelet marks that containerReady=false. - The kubelet sets the Pod condition
Ready=False. The app container is still running and still passing its own probe. - The endpoints controller removes the Pod IP from the EndpointSlice.
- kube-proxy stops sending traffic there. Clients get 503s from the remaining Pods, or connection refused if this was the only replica.
kubectl get podshowsREADY 1/2;kubectl get endpointsliceno longer lists the IP.
What to do instead
Use an init container for finite prerequisite work: it runs to completion, in order, before the app containers start. Use a native sidecar for continuous support whose lifecycle must bracket the app's. Keep anything independently deployed, scaled or owned in its own Deployment behind a Service: you pay a network hop and lose localhost, and you gain independent rollouts, an HPA per process, and a blast radius of one.
Before merging, test the couplings: kill the app container and watch the sidecar, kill the sidecar and watch the app, then check the Pod's QoS class and its endpoint membership after each.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.