Why Kubernetes Exists

Docker solved the "it works on my machine" problem by packaging applications into containers. But running containers in production at scale revealed new problems: What happens when a container crashes? How do you distribute traffic across 50 container instances? How do you update your app with zero downtime? How do you scale automatically during traffic spikes?

Kubernetes (originally built by Google, now maintained by the CNCF) is the orchestration layer that solves these problems. You describe the desired state of your system in YAML files. Kubernetes continuously works to make actual state match desired state.

Kubernetes Architecture

K8s cluster architecture ┌─────────────────────────────────────────────────────┐ │ Control Plane (Master) │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────┐ │ │ │API Server│ │Scheduler │ │Controller│ │ etcd │ │ │ │(kubectl) │ │ │ │ Manager │ │(state)│ │ │ └──────────┘ └──────────┘ └──────────┘ └───────┘ │ └─────────────────────────┬───────────────────────────┘ │ ┌─────────────────┼─────────────────┐ ▼ ▼ ▼ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ Worker Node │ │ Worker Node │ │ Worker Node │ │ kubelet │ │ kubelet │ │ kubelet │ │ kube-proxy │ │ kube-proxy │ │ kube-proxy │ │ [Pod][Pod] │ │ [Pod][Pod] │ │ [Pod][Pod] │ └──────────────┘ └──────────────┘ └──────────────┘

Control Plane Components

  • API Server: The front door — all kubectl commands and internal communication go through it
  • Scheduler: Decides which node to place new Pods on (based on resources, affinity, taints)
  • Controller Manager: Runs controllers that watch state and reconcile (ReplicaSet controller ensures N pods are running)
  • etcd: The cluster's distributed key-value store — holds all cluster state (the single source of truth)

Worker Node Components

  • kubelet: Agent on each node — communicates with control plane, manages Pods on the node
  • kube-proxy: Manages network rules for routing traffic to Pods
  • Container runtime: containerd or CRI-O — actually runs the containers

Core Kubernetes Objects

ObjectPurposeManages
PodSmallest deployable unit — wraps 1+ containersContainers directly
DeploymentDeclarative updates for Pods — rolling deploysReplicaSet → Pods
ServiceStable network endpoint for a set of PodsPod networking/DNS
ConfigMapNon-secret configuration dataConfig files, env vars
SecretSensitive configuration (passwords, tokens)Base64-encoded data
IngressHTTP routing rules — hostname/path to ServiceExternal HTTP traffic
PersistentVolumeStorage independent of Pod lifecycleDisk storage
HorizontalPodAutoscalerAuto-scales Pods based on CPU/memory/custom metricsDeployment replicas
NamespaceLogical cluster partitioningResource isolation

Deployment YAML Example

Kubernetes Deployment — nginx example apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 # 3 Pod instances selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.26 ports: - containerPort: 80 resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m" --- apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: nginx # routes to Pods with this label ports: - port: 80 targetPort: 80 type: LoadBalancer # provision cloud load balancer

Kubernetes vs Docker Compose

PropertyDocker ComposeKubernetes
ScopeSingle hostMulti-node cluster
Self-healingNoYes — restarts crashed containers
Auto-scalingNoYes — HPA
Rolling updatesManualAutomatic with zero downtime
Load balancingBasic (via ports)Native Service + Ingress
High availabilityNoYes — multi-node, redundant
ComplexityLowHigh
Best forLocal developmentProduction at scale

Start with Docker Compose for Development

Do not try to develop locally with Kubernetes — it is too heavy. Use Docker Compose for local development. Use Kubernetes for staging and production. Helm charts and kustomize can manage K8s YAML for different environments. minikube and kind run a local K8s cluster for testing K8s-specific features.

Kubernetes Is Not for Every App

Kubernetes has significant operational overhead — it requires K8s expertise, YAML proficiency, and ongoing maintenance. For small teams or early-stage products, managed platforms like Heroku, Railway, Render, or AWS App Runner offer similar benefits with far less complexity. Adopt Kubernetes when your scale or organizational structure genuinely requires it.

How We Research and Update This Guide

We test the underlying formula or workflow, compare outputs with reliable references, and revise examples whenever the page content changes.

  • The workflow or formula is tested directly in the tool and compared against independent reference examples.
  • Examples are kept practical so readers can verify the result without hidden assumptions.
  • Pages are revised whenever the interface, calculation flow, or surrounding guidance materially changes.

Frequently Asked Questions — Kubernetes