How do you decide whether two processes belong in the same Kubernetes Pod or in two separate Pods? Give the criteria you apply and what each choice costs you.
answer
- Pod = unit of scheduling, scaling, rollout, blast radius
- different scaling ratio -> different Pods
- localhost or shared files -> same Pod
- co-location couples releases and QoS
- over-packing vs under-packing
basics
~20 sSame Pod when they must share fate, scale 1:1, and need localhost or a shared filesystem. Separate Pods when they scale, release or fail independently. A Pod is the unit of scheduling, scaling, rollout and blast radius, so co-locating couples all four at once.
solid answer
~60 sThe Pod is the atom of scheduling, scaling, rollout and failure. Putting two processes in one Pod couples **all four**, so I ask: - **Do they scale at the same ratio?** If I would ever want 3 of one and 10 of the other, they are separate Pods. - **Must they share a filesystem or a port space?** File tailing and localhost-only protocols are genuine reasons to co-locate; little else is. - **Do they share fate?** If one is useless without the other *on this node*, one Pod. - **Do they release independently?** One Pod means one shared rollout - any change to either ships a new Pod of both. - **What is the blast radius?** A crash-looping companion recycles the Pod, and its requests and limits are added to the Pod's scheduling footprint and QoS class. Costs: co-location buys latency, shared volumes and atomic lifecycle at the price of independent scaling, independent releases and isolation. Separate Pods buy independence at the price of a network hop, service discovery and no shared filesystem.
go deeper
Say the default is one application per Pod, and extra containers only when they must share files or localhost with the main one.
Add the concrete coupling: same node, same scale factor, same rollout, shared grace period and summed resource requests.
Argue from operational consequences - scaling ratio, release cadence, eviction and QoS, blast radius - and give a worked example each way.
Turn it into policy: a stated co-location rule, an approved catalogue of co-tenant patterns with resource caps, DaemonSets as the alternative for fleet-wide agents, and an explicit account of what independence is being traded for latency.
## Why this is a judgement call The Pod is not just a packaging convenience; it is the boundary at which Kubernetes makes four decisions simultaneously: 1. **Scheduling** - the Pod is placed as a unit and its resource requests are the *sum* of its containers, so a fat companion can make the Pod unschedulable on smaller nodes. 2. **Scaling** - replicas multiply the whole Pod. You cannot have more of container B than of container A within one Pod. 3. **Rollout** - changing any container's image produces a new Pod template hash and rolls the whole thing. 4. **Failure and lifecycle** - containers share the sandbox, the grace period and eviction. QoS class is computed across the Pod, so one container without limits changes the eviction risk for all of them. A decision to co-locate accepts coupling on all four axes in exchange for three benefits only: `localhost` networking (no hop, no discovery), shared volumes, and atomic co-lifecycle. ## The criteria I actually apply **Scaling ratio.** The sharpest test. If two components have different load profiles - an API server and an image resizer - they must scale independently, which means separate Pods and separate Deployments. **Communication substrate.** Do they *require* a shared filesystem or shared network namespace? A log shipper tailing files, a proxy intercepting the app's loopback traffic, a helper that must observe a local socket - those are impossible across Pods without extra machinery. Two services talking HTTP are not: a Service plus a network hop is the normal answer. **Fate sharing.** Ask: "if the main container is gone from this node, is the companion still useful here?" If not, co-locate. A warm-cache loader for *this* instance shares fate; a shared cache does not. **Release independence and ownership.** If two teams ship on different cadences, one Pod forces their release trains together and makes rollbacks ambiguous. A platform-owned agent versioned with the app is a fine co-tenant - though a per-node DaemonSet is usually the better home for a fleet-wide agent, since one instance per node beats one per Pod for footprint. **Resource and isolation cost.** Each co-located container adds to the Pod's requests, competes inside the Pod's limits, and can push the Pod into a worse QoS class or off smaller nodes. High-memory companions are the usual regret. **Blast radius.** A companion in CrashLoopBackOff keeps the Pod permanently not-fully-healthy, and its OOM can tip the node into memory pressure. Ask what the failure of the *lesser* component should do to the *greater* one; if the honest answer is "nothing", separate them. ## The two failure modes **Over-packing** - bundling an app, its database and a queue into one Pod because "they are the same product". The result is an unscalable, unrollable monolith with a shared blast radius, which silently loses you the reason Kubernetes was adopted. **Under-packing** - splitting a helper that genuinely needs the app's files or loopback into its own Pod, then reinventing the sharing with a network filesystem, a hostPath or a shared PVC. That trades a simple co-location for a distributed-systems problem. ## How I would answer as an architect State the decision rule crisply - *co-locate only for fate sharing plus a physical need for a shared namespace or filesystem; otherwise separate* - then name what is given up in each direction, and finish with the platform-level standard: a small approved catalogue of co-tenant patterns (log/metrics agent, local proxy, file-sync helper) with capped resource requests, and everything else as its own workload. A rule, its costs, and a governance answer is what separates a principal answer from a list of patterns.
- A team wants a metrics agent alongside every application container. Would you co-locate it or run it per node?If the agent only needs data the node exposes, a DaemonSet is better: one instance per node instead of one per Pod cuts memory and connection count dramatically. Co-locate only when the agent must read the app's own files or loopback socket, or needs per-Pod identity and credentials.
- What does co-locating a memory-hungry companion do to scheduling and eviction?The Pod's requests become the sum of its containers, so it needs a node that can fit both, which can make it unschedulable on smaller nodes. If any container lacks limits the Pod's QoS class degrades to Burstable, making it a likelier eviction target under node memory pressure - and eviction takes the primary container with it.
Deciding on co-location is like deciding whether two people should share a car to work: worth it only if they leave and return at the same times and go to the same place - otherwise one is always waiting on the other.
saying these in an interview costs you the question
- Co-locating components purely because they belong to the same product or team
- Ignoring that containers in one Pod cannot scale independently
- Forgetting that Pod resource requests are the sum of all containers
- Splitting a file-sharing helper into another Pod and re-creating the coupling with cross-Pod storage
- Assuming a companion container's crash is harmless to the main container