Labs · DevOps
Lab: Create a kind Cluster, Apply a Deployment and Service, and Reach the App with kubectl port-forward
Course: DevOps · Chapter 15: Kubernetes Introduction · Lesson: 15.13 Lab: kind cluster, deploy, curl
Chapter 15 explains Pod, Deployment, Service and kubectl verbs; this lab runs them on your laptop.
Chala mitrano! Kubernetes shikayla cloud bill nako. kind ne laptop var cluster banvuya.
Suppose we are…
Suppose we are on an Instagram-style team moving from Docker Compose to Kubernetes. Before touching a cloud cluster that costs money, every developer needs a safe place to practise kubectl. kind runs a full Kubernetes cluster inside Docker on your laptop.
In this lab we create a cluster, deploy nginx with two replicas behind a Service, and reach it from the laptop with port-forward.
Goal of this lab
By the end you will have:
- A running kind cluster named
lab. - A Deployment with 2 ready Pods and a Service with endpoints.
- A curl to
localhost:8080that returns the nginx page.
What you need
- Docker running.
kindandkubectlinstalled (kind version,kubectl version --client).- 40 minutes.
Part 1: The cluster
Create the cluster:
kind create cluster --name lab kubectl cluster-info --context kind-lab kubectl get nodesWhat you should see: one node
lab-control-planewith STATUSReady.
Part 2: Deploy
Save the Deployment and Service:
web.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: web labels: { app: web } spec: replicas: 2 selector: matchLabels: { app: web } template: metadata: labels: { app: web } spec: containers: - name: web image: nginx:1.27 ports: - containerPort: 80 resources: requests: { cpu: 50m, memory: 64Mi } limits: { cpu: 200m, memory: 128Mi } readinessProbe: httpGet: { path: /, port: 80 } periodSeconds: 5 --- apiVersion: v1 kind: Service metadata: name: web spec: selector: { app: web } ports: - port: 80 targetPort: 80Apply it and watch the Pods start:
kubectl apply -f web.yaml kubectl get pods -l app=web -wWhat you should see: two Pods going to
Runningwith READY1/1. Press Ctrl+C to stop watching.Look at the Service and its endpoints:
kubectl get svc web kubectl get endpoints webWhat you should see: a ClusterIP and two Pod IPs on port 80 under endpoints.
Part 3: Reach it and read it
Forward a laptop port to the Service (keep this terminal open):
kubectl port-forward svc/web 8080:80In a second terminal:
curl -s localhost:8080 | head -n 4What you should see:
<title>Welcome to nginx!</title>Read events and logs:
kubectl describe deploy web | tail -n 8 kubectl logs -l app=web --tail 5What you should see: events about scaling the ReplicaSet, and nginx access-log lines from your curl.
Kill one Pod and watch Kubernetes replace it:
kubectl delete pod -l app=web --wait=false | head -n 1 kubectl get pods -l app=webWhat you should see: a new Pod with a new name; the Deployment keeps 2 replicas.
Clean up
Stop port-forward with Ctrl+C and delete the cluster:
kind delete cluster --name lab kind get clustersWhat you should see:
No kind clusters found.
Ravindra Bagale's Tip
Always write YAML and use kubectl apply -f. Commands like kubectl run are fine for a quick test, but YAML in Git is what a team can review.
Common mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Service selector does not match Pod labels | endpoints is empty, curl fails | Make selector equal to the template labels |
ImagePullBackOff | Pods never start | Check the image name and tag with kubectl describe pod |
| Closing the port-forward terminal | curl gets connection refused | Keep it running in its own terminal |
| Deleting Pods to "restart" in production | Short outage if replicas=1 | Use kubectl rollout restart deploy/web |
Self-check checklist
0 of 5 done
Try-at-home challenge
Scale to 4 replicas with kubectl scale deploy/web --replicas=4, then change it back by editing replicas in web.yaml and applying again. Which way would your team prefer, and why?
Samajla ka? Cluster on the laptop, YAML in Git, kubectl to read. Aata pudhe jaauya rolling updates.