zkt25/z2/README.md

2.8 KiB

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-deployment
  • backend-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-service
  • backend-service
  • postgres-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:alpine for frontend
  • python:3.11-slim for backend
  • postgres:15 for 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.yaml
  • service.yaml
  • statefulset.yaml
  • prepare-app.sh
  • start-app.sh
  • stop-app.sh
  • README.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:

http://localhost:8080

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:

Namespace

Deployment

StatefulSet

Service

PersistentVolume

PersistentVolumeClaim