Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 212 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
@@ -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)
50 changes: 50 additions & 0 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file added k8s/screenshots/all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/deployment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/nodes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/pods.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/rollback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/rollout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/scaling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added k8s/screenshots/services.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions k8s/service.yml
Original file line number Diff line number Diff line change
@@ -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
Loading