What Is Kubernetes?
Kubernetes (K8s) is an open-source container orchestration platform that automates deploying, scaling, and managing containerized applications. Docker packages an app into a container, but running hundreds of containers across many machines means deciding where each one runs, restarting it when it crashes, rolling out new versions without downtime, and adding copies when traffic spikes. Kubernetes handles all of that. Google open-sourced it in 2014, and it is now the standard way to run containers in production.
Kubernetes Architecture: Control Plane and Worker Nodes
A Kubernetes installation is called a cluster, and it is made of two kinds of machines:
- Control plane: manages the cluster. The API server takes your requests, etcd stores the cluster state, the scheduler picks a node for each new Pod, and controllers keep the cluster matching what you asked for.
- Worker nodes: run your applications. Each node runs a
kubeletagent that starts and monitors containers.
Kubernetes Pods, Deployments, and Services
- Pod: the smallest deployable unit, wrapping one or more containers. Pods are disposable: when one dies, its replacement gets a new name and a new IP.
- Deployment: declares which container image to run and how many replicas you want. It keeps that many Pods running, performs rolling updates, and can roll back a bad release.
- Service: gives a group of Pods one stable address and load-balances traffic across them, so nothing depends on a Pod's changing IP.
Kubernetes Deployment and Service YAML Example
Kubernetes is declarative: you describe the desired state in YAML, and the cluster makes it happen. This manifest runs three replicas of an nginx web server and exposes them through a Service. The Service finds its Pods through the app: web label.
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: nginx:1.27
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
If a Pod or a whole node fails, the controllers notice the gap between the desired state and what is running, and create replacements. This self-healing behavior is one of the main reasons teams adopt Kubernetes.
Basic kubectl Commands
kubectl is the command-line tool for talking to a Kubernetes cluster:
kubectl apply -f app.yaml # create or update resources
kubectl get pods # list running Pods
kubectl scale deployment/web --replicas=5
kubectl rollout undo deployment/web # roll back a bad release
When to Use Kubernetes
Kubernetes is worth it when you run many services that need to scale and deploy independently. For one or two small apps, a PaaS or Docker Compose is much less work. If you do adopt it, use a managed Kubernetes service such as Amazon EKS, Google GKE, or Azure AKS so the cloud provider runs the control plane.