What it is
Container orchestration is the automation that decides where containers run across a fleet of machines, keeps the right number of them running, and replaces them with new versions safely. Kubernetes is the most widely used orchestrator; Nomad, Amazon ECS and others solve the same problems. This lesson looks at the three jobs every orchestrator does: scheduling, self-healing and rollouts.
Why it exists
On one host you can start containers by hand. On fifty hosts with hundreds of services, someone has to decide which machine has room for which container, notice when a machine dies and restart its work elsewhere, and roll out releases several times a day without outages. Doing that by hand is slow and error-prone; an orchestrator does it continuously from a declared desired state.
How it works
Requests and limits. Each container declares requests (the CPU and memory it is guaranteed) and usually limits (the most it may use). CPU above the limit is throttled; memory above the limit gets the container OOM-killed. The scheduler places pods by comparing requests with each node's allocatable capacity, not with live usage.
Scheduling. For each pending pod the scheduler filters nodes that can host it (enough free requests, matching node selectors and affinity, tolerated taints, topology spread rules), then scores the survivors and binds the pod to the best one. Scoring strategies differ: least allocated spreads pods onto emptier nodes; most allocated packs them onto fuller ones (bin packing). A pod that fits on no node stays Pending, even if the cluster has enough free capacity in total spread across nodes (fragmentation). A cluster autoscaler can add nodes for Pending pods and remove nodes that packing has emptied. Bound pods are not moved again by the scheduler; tools such as the descheduler can evict pods so they are placed again.
Self-healing. Controllers compare desired state (a Deployment says 3 replicas) with actual state (2 ready pods) and act to close the gap: create a pod, which the scheduler then places. Container crashes are restarted locally by the node agent; node failures lead to replacement pods on other nodes once the failed node's pods are evicted.
Rollout strategies.
- Rolling update: replace pods a few at a time.
maxSurge(extra pods allowed) andmaxUnavailable(pods that may be missing) set the pace. Cheap and gradual, but the only gate is readiness, so a release that is "ready" but wrong spreads to everyone. - Blue-green: run the new version (green) as a complete second environment next to the old (blue), then switch all traffic at once. Rollback is switching back. Needs double capacity during the release and exposes all users at the switch.
- Canary: send a small share of traffic (by weight, header or user cohort) to the new version, compare its error rate and latency with the stable version, and either increase the share in stages or abort. Blast radius equals the canary's share; needs good metrics and automation.
Traffic shares come from replica counts (crude), weighted load balancing, an ingress or Gateway API route with weights, or a service mesh. Progressive delivery controllers (Argo Rollouts, Flagger) automate the shift-wait-analyse loop.
When to use it
- More services or hosts than you can place and restart by hand.
- Frequent releases that must not cause downtime.
- Mixed workloads (web, batch, jobs) that should share machines efficiently.
- Canary releases for anything where a bad release is expensive: payments, sign-in, core APIs.
When not to
- One or two services on a couple of machines: a managed platform or simple VMs are easier.
- Canary analysis without trustworthy metrics: a canary nobody watches is a slow rolling update.
- Blue-green for stateful systems whose data cannot be shared or switched cleanly between two environments.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Packing (most allocated) | Fewer nodes, less fragmentation, room for big pods | Larger blast radius per node, more contention |
| Spreading (least allocated) | Headroom everywhere, smaller blast radius | More nodes, fragmented free capacity |
| Rolling update | No extra environment, gradual | Readiness is the only gate; old and new run side by side |
| Blue-green | Instant switch and rollback | Double capacity; all users exposed at once |
| Canary | Small blast radius, data-driven decisions | Slower releases, needs metrics, routing and automation |
Alternatives
- Recreate: stop everything, start the new version. Simple, with downtime; acceptable for some internal or batch systems.
- Feature flags: deploy code dark and release features separately from deploys; complements any rollout strategy.
- Shadow (mirrored) traffic: send a copy of real requests to the new version and discard its responses; tests behaviour without user impact, but side effects need care.
- Managed platforms with built-in traffic splitting (Cloud Run revisions, App Service slots).
Failure modes
- Pending pods: requests too large for any node, or no headroom left after a node failure.
- Requests too low: nodes are overcommitted and pods compete for CPU or are OOM-killed under load.
- CPU limits too low: throttling and latency spikes while the node is idle.
- Shallow readiness: a broken release passes readiness and a rolling update ships it to everyone.
- Dependency order: new code needs a schema, API or config that is not deployed yet.
- Canary too small or too short: not enough requests to see a difference; errors in rare paths slip through.
- Blue-green with shared state: both versions write to the same database with incompatible schemas.
In production
Set requests from measured usage and memory limits close to them; be cautious with CPU limits. Keep spare capacity (or a cluster autoscaler) so replacements are not stuck Pending, and spread replicas across nodes and zones. Use readiness probes that reflect real ability to serve, PodDisruptionBudgets for maintenance, and canaries with automated analysis on error rate and latency for important services. Make schema and API changes backwards compatible (expand, migrate, contract), and deploy dependencies before the code that uses them.
Common misconceptions
- "The scheduler looks at CPU usage." It looks at requests and allocatable capacity.
- "Enough free CPU in the cluster means the pod will run." It must fit on one node.
- "A rolling update is safe because it is gradual." It is gradual, but it only stops for readiness failures.
- "Blue-green is always safer than canary." It rolls back faster but exposes every user the moment you switch.
- "Restarting the pod fixes a bad release." A restart runs the same image with the same missing dependency.
Interview angle
Explain how a scheduler places work (requests, filter, score) and why a pod can be Pending in a half-empty cluster. Describe self-healing as reconciliation. Compare rolling, blue-green and canary on blast radius, rollback time and cost, and say which you would use for a payment service and why (canary with automated analysis, plus backwards-compatible schema changes). Being able to compute a canary's traffic share from weights, and to say what metric would abort it, is a strong signal.
Model assumptions
This lesson uses a simplified model, not a benchmark. Web pods are simulated servers with 4 workers and a 50 ms mean service time (lognormal, cv 0.35), about 80 req/s each; traffic is Poisson. The Service uses smooth weighted round robin; its health check stands for readiness (every 250 ms, 2 failures remove, 2 successes add). The broken release is modelled as v2 calling a dependency that is down, so every request it serves fails while its readiness probe passes. The scheduler, the batch and ml pods and the CPU arithmetic are a scripted illustration, not a simulated scheduler. Pod starts, node loss, drains and weight changes are timed actions on a compressed timeline. Utilisation is the fraction of busy workers.