Kubernetes (K8s) is the industry-standard container orchestration platform. It automates deployment, scaling, and management of containerised applications.
Running one container on one server is easy. Running thousands of containers across hundreds of servers is not. Kubernetes solves:
┌─────────────────────────────────────────────────┐
│ Kubernetes Cluster │
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ Control Plane │ │
│ │ ┌──────────┐ ┌───────┐ ┌──────────┐ │ │
│ │ │ API Server│ │ etcd │ │ Scheduler│ │ │
│ │ └──────────┘ └───────┘ └──────────┘ │ │
│ └─────────────────────────────────────────┘ │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Node 1 │ │ Node 2 │ │ Node 3 │ │
│ │ ┌──────┐ │ │ ┌──────┐ │ │ ┌──────┐ │ │
│ │ │ Pod │ │ │ │ Pod │ │ │ │ Pod │ │ │
│ │ └──────┘ │ │ └──────┘ │ │ └──────┘ │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────┘
The smallest deployable unit — one or more containers that share networking and storage.
1apiVersion: v1
2kind: Pod
3metadata:
4 name: my-app
5spec:
6 containers:
7 - name: app
8 image: my-app:1.0
9 ports:
10 - containerPort: 3000Manages a set of identical Pods. Handles rolling updates and rollbacks.
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: my-app
5spec:
6 replicas: 3 # Run 3 Pods
7 selector:
8 matchLabels:
9 app: my-app
10 template:
11 metadata:
12 labels:
13 app: my-app
14 spec:
15 containers:
16 - name: app
17 image: my-app:1.0
18 ports:
19 - containerPort: 3000
20 resources:
21 requests:
22 cpu: "100m"
23 memory: "128Mi"
24 limits:
25 cpu: "250m"
26 memory: "256Mi"Provides a stable network endpoint to reach a set of Pods.
1apiVersion: v1
2kind: Service
3metadata:
4 name: my-app-svc
5spec:
6 selector:
7 app: my-app
8 ports:
9 - port: 80
10 targetPort: 3000
11 type: ClusterIP # or LoadBalancer for external access1kubectl get pods # List pods
2kubectl get deployments # List deployments
3kubectl describe pod my-app # Detailed info
4kubectl logs my-app-abc123 # Pod logs
5kubectl exec -it my-app-abc123 -- sh # Shell into pod
6kubectl apply -f deployment.yaml # Apply config
7kubectl scale deploy/my-app --replicas=5 # Scale up
8kubectl rollout undo deploy/my-app # Rollback