| .. | ||
| backend | ||
| frontend | ||
| deployment.yaml | ||
| namespace.yaml | ||
| prepare-app.sh | ||
| README.md | ||
| service.yaml | ||
| start-app.sh | ||
| statefulset.yaml | ||
| stop-app.sh | ||
Zadanie 2 - Kubernetes web application
This project deploys a simple web application into Kubernetes. The user enters a name in the browser, the frontend sends it to the backend API, and the backend stores the value in PostgreSQL. The saved names are then displayed back in the browser.
Used containers
z2-frontend:latest- custom Nginx image serving the static frontend and proxying API requests to the backend service.z2-backend:latest- custom Node.js and Express API image that stores and reads user data from PostgreSQL.postgres:15-alpine- database container running inside a StatefulSet with persistent storage.
Kubernetes objects
Namespace zkt26-z2- isolates all application resources into one namespace.Deployment backend-deployment- runs the backend API container.Deployment frontend-deployment- runs the frontend Nginx container.Service backend-service- exposes the backend inside the cluster.Service frontend-service- exposes the frontend on NodePort30080.Service postgres-service- stable network endpoint for PostgreSQL.PersistentVolume postgres-pv- host storage for PostgreSQL data.PersistentVolumeClaim postgres-pvc- binds storage for the database pod.StatefulSet postgres-statefulset- runs PostgreSQL with persistent data.
Networks and volumes
The application uses the default Kubernetes cluster networking. Pods communicate with each other through Kubernetes services:
frontend-servicefor browser accessbackend-servicefor frontend to backend communicationpostgres-servicefor backend to database communication
Persistent data is stored using:
PersistentVolume postgres-pvPersistentVolumeClaim postgres-pvc
The volume uses hostPath at /tmp/zkt26-postgres-data, so the database data remains available even after the pod restarts.
Container configuration
The frontend container is based on Nginx and includes a custom nginx.conf that proxies /api/* requests to the backend service.
The backend container uses environment variables for the database connection:
DB_HOST=postgres-serviceDB_PORT=5432DB_USER=userDB_PASSWORD=passwordDB_NAME=mydb
The PostgreSQL container is configured with:
POSTGRES_USER=userPOSTGRES_PASSWORD=passwordPOSTGRES_DB=mydb
How to prepare, start, stop and delete the application
Run the commands from the z2 directory:
chmod +x prepare-app.sh start-app.sh stop-app.sh
./prepare-app.sh
./start-app.sh
To stop and delete the application:
./stop-app.sh
How to pause the application
The application can be paused by scaling deployments and the stateful set to zero:
kubectl scale deployment frontend-deployment --replicas=0 -n zkt26-z2
kubectl scale deployment backend-deployment --replicas=0 -n zkt26-z2
kubectl scale statefulset postgres-statefulset --replicas=0 -n zkt26-z2
To start it again:
kubectl scale deployment frontend-deployment --replicas=1 -n zkt26-z2
kubectl scale deployment backend-deployment --replicas=1 -n zkt26-z2
kubectl scale statefulset postgres-statefulset --replicas=1 -n zkt26-z2
How to open the web application
After starting the application in a standard Kubernetes environment, open the browser at:
http://localhost:30080
If you are using Minikube in WSL with the Docker driver, get the real browser URL with:
minikube service frontend-service -n zkt26-z2 --url
Keep that terminal open and open the printed URL in the browser.
If your Kubernetes environment does not expose NodePort on localhost directly, or if you want a fixed local port, use:
kubectl port-forward service/frontend-service 8080:80 -n zkt26-z2
Then open:
http://localhost:8080