DevOps

What is Kubernetes?

An open-source container orchestration platform (K8s) that automates deploying, scaling, networking, and healing containerised applications across a cluster of machines.

Definition

Kubernetes is an open-source platform for running containerised applications across a cluster of machines. You declare the state you want (run three copies of this image, expose them on port 80, give each 512 MiB of memory) and Kubernetes continuously works to make the cluster match: it restarts crashed containers, reschedules them when a node fails, and rolls out new versions gradually. Google open-sourced it in 2014, drawing on its internal Borg system, and it is now maintained under the Cloud Native Computing Foundation (CNCF). What is K8s? Just an abbreviation: K, then the eight letters 'ubernete', then s. The name comes from the Greek word for helmsman or pilot, which is why the logo is a ship's wheel. Kubernetes in simple words: Docker builds and runs containers on one machine; Kubernetes decides which machines run which containers and keeps them running. So Kubernetes vs Docker is not an either-or choice. Docker (or any OCI image builder) produces images, and Kubernetes runs them through a container runtime such as containerd or CRI-O. Kubernetes removed its built-in Docker Engine integration (dockershim) in version 1.24, but images built with Docker run unchanged. The core objects are few. A Pod is the smallest deployable unit: one or more containers that share a network address and storage. A Deployment manages a set of identical Pods through a ReplicaSet and handles rolling updates and rollbacks. A Service gives those Pods a stable virtual IP and DNS name and load-balances across them, since individual Pods come and go. An Ingress or Gateway routes external HTTP traffic to Services. ConfigMaps and Secrets inject configuration, Namespaces partition a cluster, and a HorizontalPodAutoscaler adds or removes Pods based on load. You talk to the cluster's API server with kubectl, the command-line client, usually by applying YAML manifests. What is Kubernetes used for? Running microservices at scale, standardising deployment across clouds and on-premises hardware, and keeping production workloads self-healing. Managed offerings (Amazon EKS, Google GKE, Azure AKS) run the control plane for you, while k3s, kind, and minikube provide lightweight clusters for edge devices and local development.

When to Use Kubernetes

Kubernetes earns its complexity when you run many services, need rolling deploys and autoscaling across several machines, want one deployment model across clouds or on-premises hardware, or have a platform team to operate it. Managed control planes (EKS, GKE, AKS) remove much of the cluster upkeep but not the learning curve of manifests, networking, and RBAC. For a single app or a handful of containers, Docker Compose on one VPS, or a managed container platform such as Cloud Run, ECS Fargate, Fly.io, or Render, is usually cheaper and simpler. Before adopting it, make sure applications are stateless or have a clear storage plan, expose health endpoints for readiness and liveness probes, and log to stdout. Use Helm or Kustomize to template manifests and a GitOps tool such as Argo CD or Flux to keep the cluster in sync with Git.

Kubernetes in Practice

  • A Deployment and Service that run three replicas of a web app: apiVersion: apps/v1 kind: Deployment metadata: name: web spec: replicas: 3 selector: matchLabels: { app: web } template: metadata: labels: { app: web } spec: containers: - name: web image: ghcr.io/acme/web:1.4.2 ports: [{ containerPort: 3000 }] --- apiVersion: v1 kind: Service metadata: name: web spec: selector: { app: web } ports: [{ port: 80, targetPort: 3000 }]
  • Everyday kubectl commands: kubectl apply -f web.yaml kubectl get pods -l app=web kubectl logs deploy/web --tail=50 kubectl scale deployment web --replicas=5 kubectl set image deployment/web web=ghcr.io/acme/web:1.4.3 kubectl rollout undo deployment/web
  • Autoscaling on CPU: kubectl autoscale deployment web --cpu-percent=70 --min=3 --max=20 This creates a HorizontalPodAutoscaler that adds Pods when average CPU use across the Deployment exceeds 70% of the containers' requested CPU.
  • Self-healing in practice: a node running two of the three web Pods loses power. Once the node is marked unreachable (a few minutes with default settings), its Pods are evicted, the Deployment's ReplicaSet creates replacements on healthy nodes, and the Service routes traffic only to Pods that pass their readiness checks. Nobody needs to intervene unless the cluster lacks spare capacity.

Common Mistakes

  • Creating bare Pods instead of Deployments. A bare Pod is not recreated if its node dies; use a Deployment, StatefulSet, or Job.
  • Omitting resource requests and limits. The scheduler overpacks nodes, the HorizontalPodAutoscaler cannot compute CPU utilisation, and one noisy container can starve its neighbours.
  • Skipping readiness and liveness probes, so traffic reaches Pods that are still starting and deadlocked containers are never restarted.
  • Assuming Secrets are encrypted. By default they are only base64-encoded in etcd; enable encryption at rest and restrict access with RBAC.
  • Adopting Kubernetes for a small app because large companies use it, then spending more time operating the cluster than building the product.

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.