Contents

Build Your First Kubernetes Cluster: A 15-Step Hands-On Lab

Deploy, debug, scale, expose, update, and roll back apps using Minikube and kubectl — with bonus challenges included

Website Visitors:

Kubernetes Hands-On Mini Lab

Goal

By the end, you’ll know how to:

  • Create & manage workloads
  • Debug pods
  • Expose services
  • Scale & update apps
  • Work with namespaces & configs

Step 0: Setup

Start a cluster (example with Minikube)

1
minikube start

Verify:

1
2
kubectl cluster-info
kubectl get nodes

Step 1: Create a Namespace

1
2
kubectl create namespace lab
kubectl get namespaces

Use it:

1
kubectl config set-context --current --namespace=lab

Step 2: Create a Deployment

1
kubectl create deployment nginx --image=nginx

Check:

1
2
3
kubectl get deployments
kubectl get pods
kubectl describe pod <pod-name>

Step 3: Inspect & Debug

View logs

1
kubectl logs <pod-name>

Execute inside container

1
kubectl exec -it <pod-name> -- /bin/bash

Inside container:

1
2
curl localhost
exit

Step 4: Expose the App

1
2
kubectl expose deployment nginx --type=NodePort --port=80
kubectl get svc

Access it:

1
minikube service nginx

Step 5: Scale the Application

1
2
kubectl scale deployment nginx --replicas=3
kubectl get pods

Step 6: Update the Application

1
2
kubectl set image deployment/nginx nginx=nginx:latest
kubectl rollout status deployment/nginx

Check history:

1
kubectl rollout history deployment/nginx

Rollback:

1
kubectl rollout undo deployment/nginx

Step 7: Apply YAML Configuration

Create file nginx.yaml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-yaml
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx-yaml
  template:
    metadata:
      labels:
        app: nginx-yaml
    spec:
      containers:
      - name: nginx
        image: nginx

Apply:

1
2
kubectl apply -f nginx.yaml
kubectl get deployments

Step 8: Edit & Patch

Edit live config

1
kubectl edit deployment nginx-yaml

Patch replicas

1
kubectl patch deployment nginx-yaml -p '{"spec":{"replicas":4}}'

Step 9: ConfigMap Practice

1
2
3
kubectl create configmap app-config --from-literal=env=dev
kubectl get configmaps
kubectl describe configmap app-config

Step 10: Check Permissions

1
kubectl auth can-i create pods

Step 11: Resource Usage (if metrics installed)

1
2
kubectl top pods
kubectl top nodes

Step 12: Port Forwarding

1
kubectl port-forward deployment/nginx 8080:80

Open:

1
http://localhost:8080

Step 13: Copy Files

1
kubectl cp <pod-name>:/etc/nginx/nginx.conf ./nginx.conf

Step 14: Explore APIs

1
2
kubectl api-resources
kubectl explain deployment

Step 15: Cleanup

1
kubectl delete namespace lab

Or:

1
kubectl delete all --all

Bonus Challenges (Important!)

Try these on your own:

Challenge 1

Create a deployment with:

1
kubectl create deployment redis --image=redis

Then expose it.


Challenge 2

Break something:

1
kubectl set image deployment/nginx nginx=invalid-image

Then debug using:

  • kubectl describe
  • kubectl logs

Challenge 3

Filter pods:

1
kubectl get pods -l app=nginx

What You Just Practiced

You used:

  • create, apply, get, describe, delete
  • logs, exec, port-forward
  • scale, rollout
  • config, auth
  • edit, patch
  • api-resources, explain

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.