diff --git a/k8s/README.md b/k8s/README.md new file mode 100644 index 0000000000..ca808e4294 --- /dev/null +++ b/k8s/README.md @@ -0,0 +1,212 @@ +# Lab 9 — Kubernetes Fundamentals + +## 1. Architecture Overview + +This project deploys a Python Flask application to Kubernetes using a production-ready configuration. + +**Architecture:** + +User → Kubernetes Service (NodePort) → Deployment → Pods (Flask App) + +* Deployment manages multiple replicas of the application +* Service provides a stable endpoint and load balancing +* Pods run containerized Python application + +**Components:** + +* 1 Deployment (devops-python) +* 5 Pods (replicas) +* 1 Service (NodePort) + +--- + +## 2. Manifest Files + +### deployment.yml + +Defines application deployment with: + +* 5 replicas for high availability +* Rolling update strategy (zero downtime) +* Resource limits and requests +* Liveness and readiness probes + +**Key decisions:** + +* `replicas: 5` — ensures scalability and fault tolerance +* `RollingUpdate` — enables zero-downtime updates +* Probes use `/health` endpoint for reliability + +--- + +### service.yml + +Defines network access to the application. + +* Type: NodePort +* Exposes app externally +* Routes traffic to Pods using label selector + +**Ports:** + +* Service port: 80 +* Container port: 5000 +* NodePort: 30007 + +--- + +## 3. Deployment Evidence + +### Cluster Info + +```bash +kubectl get nodes +``` + +### Resources + +```bash +kubectl get all +``` + +### Pods + +```bash +kubectl get pods -o wide +``` + +### Services + +```bash +kubectl get svc +``` + +### Deployment Details + +```bash +kubectl describe deployment devops-python +``` + +### Application Test + +```bash +kubectl port-forward service/devops-python-service 8080:80 +curl http://localhost:8080 +``` + +--- + +## 4. Operations Performed + +### Deploy application + +```bash +kubectl apply -f k8s/deployment.yml +kubectl apply -f k8s/service.yml +``` + +### Scaling + +```bash +kubectl scale deployment/devops-python --replicas=5 +``` + +### Rolling Update + +```bash +kubectl apply -f k8s/deployment.yml +kubectl rollout status deployment/devops-python +``` + +### Rollback + +```bash +kubectl rollout undo deployment/devops-python +``` + +--- + +## 5. Production Considerations + +### Health Checks + +* Liveness probe ensures container restart on failure +* Readiness probe ensures traffic is sent only to ready Pods + +### Resource Management + +* CPU and memory limits prevent resource exhaustion +* Requests ensure proper scheduling + +### Improvements for Production + +* Use Ingress instead of NodePort +* Add TLS/HTTPS +* Use Horizontal Pod Autoscaler +* Integrate with Prometheus and Grafana + +--- + +## 6. Monitoring Strategy + +* Logs: Loki + Promtail (Lab 7) +* Metrics: Prometheus (Lab 8) +* Dashboards: Grafana + +This provides full observability: + +* Logs → debugging +* Metrics → performance monitoring + +--- + +## 7. Challenges & Solutions + +### Issue: ImagePullBackOff + +**Cause:** Kubernetes could not find local Docker image +**Solution:** + +```bash +kind load docker-image devops-python:latest +``` + +--- + +### Issue: Service not accessible + +**Cause:** NodePort not exposed in kind +**Solution:** + +```bash +kubectl +``` + +## 📸 Screenshots + +### Cluster & Nodes +![Nodes](screenshots/nodes.png) + +### All Resources +![All Resources](screenshots/all.png) + +### Deployment +![Deployment](screenshots/deployment.png) + +### Pods +![Pods](screenshots/pods.png) + +### Services +![Services](screenshots/services.png) + +### Application Working +![App](screenshots/app.png) + +### Scaling +![Scaling](screenshots/scaling.png) + +### Rolling Update +![Rollout](screenshots/rollout.png) + +### Rollback +![Rollback](screenshots/rollback.png) \ No newline at end of file diff --git a/k8s/deployment.yml b/k8s/deployment.yml new file mode 100644 index 0000000000..52ea5c4538 --- /dev/null +++ b/k8s/deployment.yml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: devops-python + labels: + app: devops-python +spec: + replicas: 5 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + selector: + matchLabels: + app: devops-python + template: + metadata: + labels: + app: devops-python + spec: + containers: + - name: devops-python + image: devops-python:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 5000 + env: + - name: VERSION + value: "v2" + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "200m" + memory: "256Mi" + livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/k8s/screenshots/all.png b/k8s/screenshots/all.png new file mode 100644 index 0000000000..0e7fb94edb Binary files /dev/null and b/k8s/screenshots/all.png differ diff --git a/k8s/screenshots/app.png b/k8s/screenshots/app.png new file mode 100644 index 0000000000..61be702733 Binary files /dev/null and b/k8s/screenshots/app.png differ diff --git a/k8s/screenshots/deployment.png b/k8s/screenshots/deployment.png new file mode 100644 index 0000000000..2348b78ae8 Binary files /dev/null and b/k8s/screenshots/deployment.png differ diff --git a/k8s/screenshots/nodes.png b/k8s/screenshots/nodes.png new file mode 100644 index 0000000000..b1cac11425 Binary files /dev/null and b/k8s/screenshots/nodes.png differ diff --git a/k8s/screenshots/pods.png b/k8s/screenshots/pods.png new file mode 100644 index 0000000000..ee53560cd8 Binary files /dev/null and b/k8s/screenshots/pods.png differ diff --git a/k8s/screenshots/rollback.png b/k8s/screenshots/rollback.png new file mode 100644 index 0000000000..7f1b9621ee Binary files /dev/null and b/k8s/screenshots/rollback.png differ diff --git a/k8s/screenshots/rollout.png b/k8s/screenshots/rollout.png new file mode 100644 index 0000000000..6d0548ded6 Binary files /dev/null and b/k8s/screenshots/rollout.png differ diff --git a/k8s/screenshots/scaling.png b/k8s/screenshots/scaling.png new file mode 100644 index 0000000000..18afd326c6 Binary files /dev/null and b/k8s/screenshots/scaling.png differ diff --git a/k8s/screenshots/services.png b/k8s/screenshots/services.png new file mode 100644 index 0000000000..f1331f83c3 Binary files /dev/null and b/k8s/screenshots/services.png differ diff --git a/k8s/service.yml b/k8s/service.yml new file mode 100644 index 0000000000..2f54f78418 --- /dev/null +++ b/k8s/service.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: devops-python-service +spec: + type: NodePort + selector: + app: devops-python + ports: + - port: 80 + targetPort: 5000 + nodePort: 30007 \ No newline at end of file