Kubernetes Essentials
Kubernetes Essentials
Orchestrating Containers at Scale
Docker runs containers on one machine. Kubernetes orchestrates containers across many machines, keeping the desired state true automatically. Define what should exist, and Kubernetes converges the cluster to match, restarting failed containers and redistributing work.
Core Objects
Three objects dominate daily work:
- Pod: the smallest unit, wrapping one or more containers that share a network and storage.
- Deployment: declares how many copies of a pod should run and manages rollouts and scaling.
- Service: a stable address that routes traffic to the pods backing a deployment, because pod IPs change constantly.
A Simple Deployment
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: myapp:1.0
ports:
- containerPort: 8000
This deployment keeps three replicas running. If a replica's container crashes, the controller creates a new pod so the count returns to three. Rolling updates swap replicas gradually so the application never goes down.
Daily Commands
kubectl get pods # list pods
kubectl get deployments # list deployments
kubectl logs web-abc123
kubectl apply -f deploy.yaml
kubectl scale deployment web --replicas=5
kubectl is the command-line client. apply -f sends a YAML file to the cluster, and scale changes the replica count on the fly.
Self-Healing and Scaling
Kubernetes constantly compares observed state with desired state and reconciles the difference. Failed pods respawn, overloaded deployments scale with more replicas, and traffic is balanced across healthy pods via the Service. That supervision is the entire point: a cluster that runs itself.
Key Points
- Kubernetes orchestrates containers across many machines.
- Pods wrap containers; Deployments manage replicas; Services give stable addresses.
- Declarative YAML describes the desired state, and the cluster converges to it.
- Self-healing restarts failed pods and maintains replica counts.
- kubectl applies, inspects, and scales cluster resources.