Containers & Kubernetes
How containers and orchestration run microservices at scale â declarative desired state, the reconciliation loop that self-heals, Pods and Services, and zero-downtime rolling updates.
Containers package applications into portable, lightweight units; Kubernetes orchestrates them across a cluster. Its core idea is declarative: you describe the desired state, and controllers continuously reconcile reality toward it â restarting failed Pods, scaling, and rolling out new versions automatically. This is what makes microservices operable at scale, with self-healing and zero-downtime deploys built in.
A container bundles an app with its exact dependencies into a portable image that runs identically on any host â solving 'works on my machine'. Unlike VMs, containers share the host kernel, so they're lightweight, start in seconds, and pack densely onto machines.
Running a handful of containers is easy; running hundreds across many machines â scheduling them, restarting failures, scaling, networking, and rolling out updates â is not. Kubernetes is the orchestrator that automates all of this across a cluster of nodes.
You declare desired state ('run 3 replicas of v2') in a manifest; you don't issue imperative commands. Controllers in the control plane continuously compare desired vs actual state and act to close the gap â if a Pod dies, a replacement is started automatically. This reconciliation loop is what gives Kubernetes self-healing.
A Pod is the smallest deployable unit (one or more containers). A Deployment manages a replica set of identical Pods. A Service gives them a stable DNS name and load-balances across them. A rolling update surges new-version Pods up and drains old ones gradually â keeping capacity available throughout for zero-downtime deploys (with instant rollback if a new version misbehaves).
Key Concepts
A lightweight, portable package of an app + its dependencies sharing the host kernel. Starts fast, runs anywhere.
Kubernetes' smallest deployable unit â one or more tightly-coupled containers sharing network and storage.
Declares a desired number of identical Pod replicas and manages rollouts/rollbacks of new versions.
Controllers continuously drive actual state toward declared desired state â the source of self-healing.
A stable DNS name + virtual IP that load-balances across a Deployment's healthy Pods.
Gradually replacing Pods with a new version while keeping capacity, enabling zero-downtime deploys.
1# Declare DESIRED state â Kubernetes continuously reconciles toward it.2apiVersion: apps/v13kind: Deployment4metadata: { name: orders-api }5spec:6 replicas: 3 # keep exactly 3 Pods running7 strategy:8 type: RollingUpdate # zero-downtime deploys9 rollingUpdate: { maxSurge: 1, maxUnavailable: 0 }10 selector: { matchLabels: { app: orders-api } }11 template:12 metadata: { labels: { app: orders-api } }13 spec:14 containers:15 - name: api16 image: registry/orders-api:v2 # change to v2 â triggers rollout17 readinessProbe: # don't send traffic until ready18 httpGet: { path: /health, port: 8080 }19 resources:20 requests: { cpu: 100m, memory: 128Mi } # scheduler placement21 limits: { cpu: 500m, memory: 256Mi }22---23# A Service gives the Pods one stable DNS name + load-balanced virtual IP.24apiVersion: v125kind: Service26metadata: { name: orders-api }27spec:28 selector: { app: orders-api }29 ports: [{ port: 80, targetPort: 8080 }]
Containers and Kubernetes are the de facto runtime for microservices, and understanding declarative state, reconciliation, Pods/Services, and rolling updates is essential for deploying and operating modern systems â and increasingly expected in interviews. The mental model (desired vs actual state) explains nearly everything Kubernetes does.
Common Pitfalls
1A Crashed Node at 3 AM â and Nobody Paged
A node hosting several service Pods dies overnight. In the old VM world this meant a pager alert and manual recovery. With Kubernetes, by the time anyone looked, the affected Pods were already running again on healthy nodes.
Hardware and processes fail unpredictably. Manual recovery is slow, error-prone, and doesn't scale across hundreds of services â and it always seems to happen at the worst time.
Because the Deployment declares 'keep N replicas running', the controller detected the lost Pods (actual < desired) and rescheduled replacements on other nodes automatically. The Service updated its endpoints to the new healthy Pods, and traffic kept flowing.
Takeaway: Declarative desired state + reconciliation gives self-healing for free. You describe what should be running; Kubernetes makes reality match it continuously, turning node failures into non-events.
2Shipping 20Ã a Day Without Downtime (and Safe Rollback)
A team wants to deploy frequently, but each release used to require a maintenance window because restarting all instances dropped requests, and a bad release meant a scramble to revert.
Replacing all instances at once causes downtime, and rolling back a faulty manual deploy is slow and risky â discouraging frequent, small releases.
Use a RollingUpdate strategy with readiness probes: Kubernetes brings up new-version Pods, waits until they pass their health check before sending traffic, then drains old Pods one batch at a time. If the new version misbehaves, kubectl rollout undo instantly reverts to the previous ReplicaSet.
Takeaway: Rolling updates with readiness probes give zero-downtime deploys and one-command rollback, making frequent, low-risk releases routine instead of a scheduled event.
Join the discussion
Comments
Loading comments...
Cookie preferences
We use essential cookies for sign-in and preferences. With your permission, we also use basic analytics to improve lessons.