DevOps

Kubernetes

An open-source container orchestration platform that automates deploying, scaling, and managing containerized applications across clusters of machines.

Kubernetes (K8s) is an open-source platform for automating the deployment, scaling, and management of containerized applications. Originally developed by Google, it's now maintained by the Cloud Native Computing Foundation (CNCF).

Core concepts include Pods (smallest deployable units, one or more containers), Deployments (manage replica sets and rolling updates), Services (stable networking for pods), ConfigMaps/Secrets (configuration management), and Ingress (HTTP routing and load balancing).

Kubernetes handles auto-scaling (scale pods based on CPU/memory/custom metrics), self-healing (restart crashed containers, replace unhealthy nodes), rolling updates (zero-downtime deployments), and service discovery (automatic DNS for services).

Managed Kubernetes services like AWS EKS, Google GKE, and Azure AKS simplify cluster management. Tools like Helm (package manager), ArgoCD (GitOps deployments), and Prometheus (monitoring) are essential parts of the Kubernetes ecosystem.

How it works

The Kubernetes documentation defines it as a portable, extensible, open source platform for managing containerized workloads and services that facilitates both declarative configuration and automation. The name is Greek for helmsman or pilot, K8s counts the eight letters between the K and the s, and Google open-sourced the project in 2014.

Everything is driven by desired state. You submit objects describing what should exist, usually as YAML through kubectl, to the API server. Controllers are control loops that watch the cluster's shared state and act to move the current state towards the desired one; a Deployment controller, for instance, changes the actual state to the desired state at a controlled rate.

The smallest deployable unit is a Pod: one or more containers with shared storage and network resources and a specification for how to run them. A Deployment manages ReplicaSets, which keep a set number of Pods running; the scheduler assigns Pods to nodes, and the kubelet on each node starts their containers. A Service gives a group of Pods one stable address and spreads traffic across them.

Self-healing falls out of the control loop. If a node fails and its Pods disappear, the running count drops below the desired replicas and the controller creates replacements elsewhere, with no separate recovery script.

Example

The Deployment example from the Kubernetes documentation: three replicas of nginx.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
kubectl apply -f nginx-deployment.yaml
kubectl get pods -l app=nginx          # three Pods
kubectl delete pod <one-of-them>       # a replacement is created
kubectl set image deployment/nginx-deployment nginx=nginx:1.16.1   # rolling update

Deleting a Pod does not reduce the count to two for long: the ReplicaSet sees fewer Pods than the three the spec asks for and starts another. Changing the image starts a rolling update, replacing Pods gradually rather than all at once.

Common confusion

What is the difference between Kubernetes and Docker?

Docker builds container images and runs containers, typically on one machine. Kubernetes schedules and manages containers across a cluster of machines, keeping the desired number running and routing traffic to them. The Kubernetes documentation is explicit that it does not deploy source code or build applications; images are built elsewhere, often with Docker in a CI pipeline, and Kubernetes runs them through a container runtime.

Is Kubernetes a platform as a service (PaaS)?

Not in the traditional sense. Its documentation says it is not an all-inclusive PaaS: it does not provide built-in databases, caches or middleware, and it does not dictate logging, monitoring or CI/CD. It provides building blocks, and many platforms are built on top of it.

Further reading

Want to learn more?

Explore more developer terms or read in-depth articles on the blog.

Browse all terms