| .. | ||
| app.py | ||
| deployment.yaml | ||
| Dockerfile | ||
| index.html | ||
| nginx.conf | ||
| prepare-app.sh | ||
| README.md | ||
| requirements.txt | ||
| service.yaml | ||
| start-app.sh | ||
| statefulset.yaml | ||
| stop-app.sh | ||
Assignment 2 - Kubernetes
Application description
This assignment demonstrates how to deploy a simple application in Kubernetes.
The application consists of:
- a frontend
- a backend
- a PostgreSQL database
The frontend displays a simple web page. The backend provides a simple Flask service. The database runs in PostgreSQL with persistent storage.
Kubernetes objects used
Namespace
z2app
The namespace is used to isolate all resources of the application.
Deployments
frontend-deploymentbackend-deployment
The frontend and backend are deployed using Deployment because they are stateless components.
StatefulSet
postgres
The PostgreSQL database is deployed using StatefulSet because it requires persistent storage.
Services
frontend-servicebackend-servicepostgres-service
Services are used for communication between components and for exposing the frontend.
Persistent storage
PersistentVolume(postgres-pv)PersistentVolumeClaim(postgres-pvc)
These resources are used to store PostgreSQL data persistently.
Container images used
nginx:alpinefor frontendpython:3.11-slimfor backendpostgres:15for database
Application architecture
- Frontend runs on port 80
- Backend runs on port 5000
- PostgreSQL runs on port 5432
The frontend is exposed through frontend-service.
The backend is available through backend-service.
The database is available through postgres-service.
Files included
deployment.yamlservice.yamlstatefulset.yamlprepare-app.shstart-app.shstop-app.shREADME.md
How to prepare the application
Run:
./prepare-app.sh
How to start the application
Run:
./start-app.sh
How to stop the application
Run:
./stop-app.sh
How to verify that the application is running
Check the pods:
kubectl get pods -n z2app
Check the services:
kubectl get svc -n z2app
Check persistent storage:
kubectl get pv kubectl get pvc -n z2app
How to access the frontend
Use port-forward:
kubectl port-forward -n z2app service/frontend-service 8080:80
Then open in browser:
How to access the backend
Use port-forward:
kubectl port-forward -n z2app service/backend-service 5000:5000
Then test:
curl http://localhost:5000 curl http://localhost:5000/health
Notes
When the application starts, pods may first appear as ContainerCreating or Pending. After a few seconds they should become Running.
Summary
This assignment shows how to deploy a multi-component application in Kubernetes using: