This repository contains hands-on practicals for learning Kubernetes locally with Minikube.
- Session 1: Environment Setup and Basic Concepts (30 minutes)
- Session 2: Deploy Your First Application (45 minutes)
- Session 3: Scaling and Updates (30 minutes)
- Session 4: Troubleshooting and Best Practices (15 minutes)
nginx-pod.yamlnginx-deployment.yamlnginx-service.yamlmongodb-deployment.yamlmongodb-service.yaml
- Windows machine
- PowerShell or Command Prompt (run as Administrator for setup tasks)
- Minikube installed
- Docker Desktop running
- VS Code installed
minikube versionExpected output (example):
minikube version: v1.36.0
commit: f8f52f5de11fc6ad8244afac475e1d0f96841df1-dirty
minikube start --driver=dockerThis command downloads Kubernetes images and starts the local cluster. The first run may take 3-5 minutes.
minikube statusExpected output (example):
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Launch Visual Studio Code.
- Open Extensions (
Ctrl+Shift+X) - Search for
Kubernetesby Microsoft - Click Install
If starting from scratch in terminal:
mkdir k8s-workshop
cd k8s-workshopNote: For this repository, you are already inside the workshop folder.
kubectl version --client
kubectl cluster-infoProject Goal: Deploy a simple NGINX web server.
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80YAML meaning:
apiVersion: Kubernetes API versionkind: Resource type (Pod)metadata: Name and labelsspec: Pod container configuration
kubectl apply -f nginx-pod.yamlkubectl get pods
kubectl describe pod nginx-pod
kubectl logs nginx-podDeployments manage replicas and rolling updates.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80Key differences vs Pod:
replicas: 3creates 3 identical podsselectordecides which pods are managedtemplatedefines pod blueprint
kubectl delete pod nginx-podkubectl apply -f nginx-deployment.yamlkubectl get deployments
kubectl get pods
kubectl get pods -wServices provide stable network access to pods.
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080Service types:
ClusterIP: Internal only (default)NodePort: Exposes on node IP + static portLoadBalancer: Cloud external load balancer
kubectl apply -f nginx-service.yamlkubectl get servicesminikube service nginx-service --url
minikube service nginx-servicekubectl scale deployment nginx-deployment --replicas=5
kubectl get pods -wkubectl scale deployment nginx-deployment --replicas=2kubectl set image deployment/nginx-deployment nginx=nginx:1.26
kubectl rollout status deployment/nginx-deploymentkubectl rollout history deployment/nginx-deploymentkubectl rollout undo deployment/nginx-deployment
kubectl rollout undo deployment/nginx-deployment --to-revision=1In this practical, you add MongoDB as a second application component.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo:7.0
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: admin
- name: MONGO_INITDB_ROOT_PASSWORD
value: password123apiVersion: v1
kind: Service
metadata:
name: mongodb-service
spec:
type: ClusterIP
selector:
app: mongodb
ports:
- protocol: TCP
port: 27017
targetPort: 27017kubectl apply -f mongodb-deployment.yaml
kubectl apply -f mongodb-service.yaml
kubectl get all| Command | Purpose |
|---|---|
kubectl get pods |
List all pods |
kubectl describe pod <name> |
Detailed pod info |
kubectl logs <pod-name> |
View container logs |
kubectl exec -it <pod> -- /bin/bash |
Open shell in pod |
kubectl delete pod <name> |
Delete a pod |
kubectl get events |
View cluster events |
kubectl top pods |
Resource usage (needs Metrics Server) |
| Status | Meaning | Action |
|---|---|---|
Pending |
Waiting for resources | Check kubectl describe |
ImagePullBackOff |
Image pull failed | Verify image name and network |
CrashLoopBackOff |
Container keeps crashing | Check kubectl logs <pod> |
Running |
Healthy | No action needed |
- Use Deployments instead of standalone Pods in production
- Label resources consistently
- Add CPU and memory resource requests/limits
- Use liveness and readiness probes
- Keep YAML files versioned in Git
- Use namespaces for environment separation
- Do not hardcode secrets in YAML; use Kubernetes Secrets/ConfigMaps
kubectl delete deployment --all
kubectl delete service --all
minikube stop
minikube delete- Set up local Kubernetes with Minikube
- Created and deployed Pods, Deployments, and Services
- Scaled workloads up and down
- Performed rolling updates and rollbacks
- Used kubectl for troubleshooting
- Deployed an app component with MongoDB