Kubernetes is the standard for running containers at scale. Learn what it is, how it works, and the core concepts every developer should know.
Kubernetes (K8s) is a system for automating deployment, scaling, and management of containerized applications.
Docker runs containers. Kubernetes runs and manages thousands of containers across hundreds of servers.
Docker: "Here's how to run one container"
Kubernetes: "Here's how to run 10,000 containers reliably"
Imagine you have a web app running in Docker. What happens when:
Kubernetes handles all of this automatically.
The smallest deployable unit in Kubernetes. A pod wraps one or more containers.
# pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: app
image: my-app:1.0
ports:
- containerPort: 3000
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"Manages a set of identical pods. Handles rolling updates and rollbacks.
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3 # run 3 pods
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: my-app:1.0
ports:
- containerPort: 3000Exposes pods to network traffic. Provides a stable IP/DNS even as pods come and go.
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app # routes to pods with this label
ports:
- port: 80
targetPort: 3000
type: LoadBalancer # creates a cloud load balancerspec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # add 1 extra pod during update
maxUnavailable: 0 # never take pods down before new ones are readyBefore update: [v1] [v1] [v1]
During update: [v1] [v1] [v2] ← new pod added, traffic shifts
[v1] [v2] [v2]
After update: [v2] [v2] [v2]
# Apply a configuration
kubectl apply -f deployment.yaml
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
# Describe a resource (detailed info)
kubectl describe pod my-app-abc123
# View logs
kubectl logs my-app-abc123
kubectl logs -f my-app-abc123 # follow
# Execute command in pod
kubectl exec -it my-app-abc123 -- sh
# Scale a deployment
kubectl scale deployment my-app --replicas=5
# Rolling update
kubectl set image deployment/my-app app=my-app:2.0
# Rollback
kubectl rolloutRunning your own Kubernetes control plane is complex. Cloud providers offer managed versions:
| Service | Provider | Notes |
|---|---|---|
| EKS | AWS | Most widely used |
| GKE | Best managed K8s, Google invented K8s | |
| AKS | Azure | Good Microsoft integration |
With managed K8s, the provider runs the control plane. You just manage worker nodes and workloads.
Use Kubernetes when:
Don't use Kubernetes when:
Kubernetes has significant operational complexity. Don't adopt it until you need it.