Kubernetes Project #2

Source: Dev.to | Jan 04, 2026 (UTC)

“Production Basics: Deployment + Service + Rolling Update”

What you will build

Browser → Service (NodePort) → Deployment → Pods (replicas=2) → nginx containers

Enter fullscreen mode

Exit fullscreen mode

What you will learn (DevOps core)

Prerequisites

Start/verify:

minikube start kubectl get nodes

Enter fullscreen mode

Exit fullscreen mode

Step 0 — Clean up from Project #1 (if you ran it)

This prevents conflicts and confusion.

kubectl delete pod hello-pod --ignore-not-found kubectl delete svc hello-service --ignore-not-found

Enter fullscreen mode

Exit fullscreen mode

Check nothing left:

kubectl get pods kubectl get svc

Enter fullscreen mode

Exit fullscreen mode

Step 1 — Create a Deployment (NOT a Pod)

A Deployment is a “manager” that ensures the desired number of Pods are always running.

Create file: deployment.yaml

apiVersion: apps/v1 kind: Deployment metadata: name: hello-deploy spec: replicas: 2 selector: matchLabels: app: hello template: metadata: labels: app: hello spec: containers: - name: nginx image: nginx:1.25 ports: - containerPort: 80

Enter fullscreen mode

Exit fullscreen mode

Apply it:

kubectl apply -f deployment.yaml

Enter fullscreen mode

Exit fullscreen mode

What each part means (important)

Verify

kubectl get deployments kubectl get pods -o wide

Enter fullscreen mode

Exit fullscreen mode

Expected:

Step 2 — Understand what Deployment created

A Deployment automatically creates:

  1. ReplicaSet (the low-level controller)
  2. Pods (the running instances)

Check:

kubectl get rs

Enter fullscreen mode

Exit fullscreen mode

Explain:

Step 3 — Expose it using a Service (stable access)

Pods get replaced and IPs change, so we use a Service.

Create file: service.yaml

apiVersion: v1 kind: Service metadata: name: hello-service spec: type: NodePort selector: app: hello ports: - port: 80 targetPort: 80

Enter fullscreen mode

Exit fullscreen mode

Apply:

kubectl apply -f service.yaml

Enter fullscreen mode

Exit fullscreen mode

What this does

Verify:

kubectl get svc kubectl describe svc hello-service

Enter fullscreen mode

Exit fullscreen mode

Key thing to check inside describe:

Step 4 — Open in the Browser

Run:

minikube service hello-service --url

Enter fullscreen mode

Exit fullscreen mode

It prints something like:

http://127.0.0.1:5xxxx

Enter fullscreen mode

Exit fullscreen mode

Open that URL in a browser → you should see Welcome to nginx!

Why this is best:

Step 5 — Prove High Availability (Replica behavior)

Delete one Pod manually:

  1. list pods:

kubectl get pods

Enter fullscreen mode

Exit fullscreen mode

  1. delete one pod:

kubectl delete pod <one-pod-name>

Enter fullscreen mode

Exit fullscreen mode

  1. watch what happens:

kubectl get pods -w

Enter fullscreen mode

Exit fullscreen mode

What you will observe:

Explain to students:

This is Kubernetes self-healing. You don’t “restart containers” manually in prod. The controller does it.

Step 6 — Scale Up (simulate traffic growth)

Scale to 5 replicas:

kubectl scale deployment hello-deploy --replicas=5

Enter fullscreen mode

Exit fullscreen mode

Check:

kubectl get pods kubectl get deployment hello-deploy

Enter fullscreen mode

Exit fullscreen mode

Expected: 5 pods running.

Explain:

Scaling is a normal DevOps operation during peak traffic.

Scale back down:

kubectl scale deployment hello-deploy --replicas=2

Enter fullscreen mode

Exit fullscreen mode

Step 7 — Rolling Update (Zero-downtime deployment)

Now you will change the image version and watch Kubernetes update pods gradually.

Update to a newer nginx (example):

kubectl set image deployment/hello-deploy nginx=nginx:1.26

Enter fullscreen mode

Exit fullscreen mode

Watch rollout:

kubectl rollout status deployment/hello-deploy kubectl get pods -w

Enter fullscreen mode

Exit fullscreen mode

What you’ll see:

Check rollout history:

kubectl rollout history deployment/hello-deploy

Enter fullscreen mode

Exit fullscreen mode

Rollback (very important skill):

kubectl rollout undo deployment/hello-deploy

Enter fullscreen mode

Exit fullscreen mode

Explain:

Rollback is what you do when a release breaks production.

Step 8 — Troubleshooting Checklist (Most important for DevOps)

Case A: Service exists but website doesn’t open

Run in this order:

  1. Are pods running?

kubectl get pods

Enter fullscreen mode

Exit fullscreen mode

  1. Are pods ready?

kubectl describe pod <pod>

Enter fullscreen mode

Exit fullscreen mode

  1. Does service have endpoints?

kubectl describe svc hello-service

Enter fullscreen mode

Exit fullscreen mode

Look for:

  1. Are labels correct?

kubectl get pods --show-labels kubectl get svc hello-service -o yaml

Enter fullscreen mode

Exit fullscreen mode

Check:

Case B: Pods stuck in Pending

kubectl describe pod <pod>

Enter fullscreen mode

Exit fullscreen mode

Typical reasons:

Case C: CrashLoopBackOff

kubectl logs <pod> kubectl describe pod <pod>

Enter fullscreen mode

Exit fullscreen mode

Look for:

What you should be able to explain after Project #2

If you can explain these, you’re at a strong DevOps level:

  1. Why Deployment is production standard, not Pod
  2. What ReplicaSet does
  3. How Service routes traffic (selector → endpoints → pods)
  4. How scaling works
  5. How rolling updates work
  6. How to rollback
  7. How to troubleshoot “service up but not reachable”

Clean up (end of lab)

kubectl delete -f service.yaml kubectl delete -f deployment.yaml

Enter fullscreen mode

Exit fullscreen mode

For further actions, you may consider blocking this person and/or reporting abuse

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

Читайте також