Lab 5 of 8 · Kubernetes
Run your app on a local Kubernetes cluster
Create a free local cluster with kind, deploy two copies of your app, watch Kubernetes heal it, and scale it.
- Time
- 60–90 minutes
- Cost
- Free: the cluster runs inside Docker on your computer.
What you learn
Kubernetes runs many copies of containers, restarts them when they fail and spreads traffic between them. It is the standard platform for running services, and increasingly for serving AI models.
- Clusters, pods, deployments and services
- Readiness checks and resource limits
- Self-healing and scaling
- kubectl for inspecting and fixing problems
In the AI era: GPU workloads and model servers (for example vLLM and KServe) are usually run on Kubernetes. Requests and limits, which you set in this lab, are how teams control what AI workloads cost.
Before you start
Finish lab 2 (you need the
ai-status-app:1.0image).Install kind and kubectl. Check with
kind versionandkubectl version --client.
Step by step
1 Create a cluster
kind runs a whole Kubernetes cluster inside a Docker container.
kind create cluster --name devops-lab kubectl get nodesYou should see:One node named
devops-lab-control-planewith statusReady.2 Load your image into the cluster
The cluster cannot see images on your computer until you load them.
kind load docker-image ai-status-app:1.0 --name devops-lab3 Describe the deployment and service
The Deployment keeps two copies running and only sends traffic to a copy once
/healthanswers. The Service gives them one stable address.apiVersion: apps/v1 kind: Deployment metadata: name: ai-status-app spec: replicas: 2 selector: matchLabels: app: ai-status-app template: metadata: labels: app: ai-status-app spec: containers: - name: app image: ai-status-app:1.0 imagePullPolicy: IfNotPresent ports: - containerPort: 8000 readinessProbe: httpGet: path: /health port: 8000 resources: requests: cpu: 50m memory: 64Mi limits: cpu: 250m memory: 256Mi --- apiVersion: v1 kind: Service metadata: name: ai-status-app spec: selector: app: ai-status-app ports: - port: 80 targetPort: 80004 Deploy it
Wait until both pods show
1/1 Running, then press Ctrl+C to stop watching.kubectl apply -f k8s/app.yaml kubectl get pods -wYou should see:Two
ai-status-app-...pods,1/1 Running.5 Reach the app
Port-forward connects your computer to the service. Leave it running and use a second terminal for curl.
kubectl port-forward service/ai-status-app 8080:80 # in a second terminal: curl http://localhost:8080/healthYou should see:{"status":"ok"}.6 Watch it heal
Delete one pod. Kubernetes notices there is one copy too few and starts a new one.
kubectl delete pod "$(kubectl get pods -l app=ai-status-app -o name | head -n 1 | cut -d/ -f2)" kubectl get podsYou should see:A brand-new pod with a young AGE, and two pods running again.
7 Scale and inspect
describeandlogsare the first two commands to run when a pod misbehaves.kubectl scale deployment ai-status-app --replicas=3 kubectl get pods kubectl describe deployment ai-status-app | head -n 20 kubectl logs deployment/ai-status-appYou should see:Three pods, and
3 desired | 3 updated | 3 total | 3 availablein the description.8 Commit, then delete the cluster
Delete the cluster when you are done; you can recreate it in a minute.
git add k8s git commit -m "Add Kubernetes deployment and service" git push kind delete cluster --name devops-lab
You are done when
You saw Kubernetes replace a deleted pod by itself.
You scaled the deployment and read
kubectl describeandkubectl logs.k8s/app.yamlis on GitHub.
We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.