DevOps Lesson 9: Kubernetes Intro
Kubernetes (K8s) orchestrates containers at scale — auto-scaling, self-healing, load balancing across hundreds of servers. The backbone of modern infrastructure.
Core Concepts
// Pod: smallest unit (1+ containers running together)
// Deployment: manages Pods (desired state, rolling updates)
// Service: network access to Pods (load balancing)
// Namespace: virtual clusters within a cluster
// ConfigMap/Secret: configuration and secrets
// Ingress: HTTP routing from outside the cluster
Deployment YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-api
spec:
replicas: 3 # run 3 copies!
selector:
matchLabels:
app: my-api
template:
metadata:
labels:
app: my-api
spec:
containers:
- name: api
image: myapp:1.0
ports:
- containerPort: 3000
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: app-secrets
key: database-url
resources:
requests: { cpu: "100m", memory: "128Mi" }
limits: { cpu: "500m", memory: "512Mi" }
---
apiVersion: v1
kind: Service
metadata:
name: my-api-service
spec:
selector:
app: my-api
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
kubectl Commands
kubectl apply -f deployment.yaml # deploy
kubectl get pods # list pods
kubectl logs my-api-abc123 # view logs
kubectl exec -it my-api-abc sh # shell into pod
kubectl scale deployment my-api --replicas=5 # scale!
kubectl rollout status deployment/my-api
kubectl rollout undo deployment/my-api # roll back!
🏋️ Practice Task
Install minikube (local Kubernetes) and kubectl. Deploy your Docker app with a Deployment (replicas:2) and Service. Access it via minikube service my-api-service –url. Scale to 3 replicas. Simulate a pod crash (kubectl delete pod
💡 Hint: minikube start. kubectl apply -f deployment.yaml. minikube dashboard for visual view.