Labs & Challenges β Linux, Docker & Kubernetes¶
Difficulty: Beginner-Intermediate Β· Estimated time: 1.5-2 hrs (all challenges)
Hands-on exercises to practice and reinforce your SRE/DevOps skills.
π§ Linux Labs¶
Lab 1 β System Investigation¶
Goal: Identify the most CPU-hungry process and investigate its cause.
Steps: 1. SSH into a test Linux VM. 2. Run:
uptime
top
ps aux --sort=-%cpu | head
strace -p <pid>
Lab 2 β Disk Usage Triage¶
Goal: Find which directory is filling the disk.
Steps: 1. Simulate filling a disk:
fallocate -l 1G /tmp/filltest
du -sh /* | sort -h
Lab 3 β Log Filtering¶
Goal: Extract only ERROR logs from a service.
Steps: 1. Create a sample log file:
echo -e "INFO start\nERROR fail1\nINFO running\nERROR fail2" > app.log
grep "ERROR" app.log
error.log.
π³ Docker Labs¶
Lab 4 β Build & Run a Simple App¶
Goal: Containerize a Python app and run it.
Steps:
1. Create app.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from Docker!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
Dockerfile:
FROM python:3.12-slim
WORKDIR /app
COPY app.py .
RUN pip install flask
CMD ["python", "app.py"]
docker build -t hello:1.0 .
docker run -p 8080:8080 hello:1.0
Lab 5 β Using Volumes¶
Goal: Persist data between container restarts.
Steps: 1. Create a volume:
docker volume create appdata
docker run -it -v appdata:/data busybox sh
echo "persistent data" > /data/test.txt
βΈοΈ Kubernetes Labs¶
Lab 6 β Deploy an App¶
Goal: Deploy the hello Docker image to Kubernetes.
Steps:
1. Push image to registry (GHCR, Docker Hub).
2. Create deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
spec:
replicas: 2
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: ghcr.io/<your-org>/hello:1.0
ports:
- containerPort: 8080
kubectl apply -f deployment.yaml
kubectl get pods
Lab 7 β Add Probes¶
Goal: Add readiness & liveness probes.
Steps: 1. Edit container spec:
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 5
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 10
kubectl describe pod <pod-name>
Lab 8 β Scale & Rollback¶
Goal: Practice scaling and rolling back a deployment.
Steps: 1. Scale:
kubectl scale deployment hello --replicas=5
kubectl get pods
kubectl rollout undo deployment hello
β Completion Checklist¶
- [ ] Comfortable using Linux CLI for triage
- [ ] Built & ran a Docker image
- [ ] Deployed and managed an app in Kubernetes
- [ ] Configured probes and scaled pods
- [ ] Rolled back a bad deploy without downtime