Go to file
2025-04-21 19:00:14 +00:00
z1 add other folders 2025-03-18 13:27:22 +00:00
z2 Téléverser les fichiers vers "z2" 2025-04-21 18:59:47 +00:00
persistent-storage.yaml Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
postgres-deployment.yaml Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
postgres-service.yaml Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
prepare-app.sh Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
README.md Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
requirements.txt Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
service.yaml Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
start-app.sh Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
statefulset.yaml Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00
stop-app.sh Téléverser les fichiers vers "/" 2025-04-21 18:58:30 +00:00

Shopping List Web Application on Kubernetes

Overview

This project deploys a Python shopping list web application using Flask and PostgreSQL on a Kubernetes cluster. The application allows users to create, track, and manage their shopping items in a persistent way. The deployment includes a Namespace, Deployments for both the web application and PostgreSQL database, a StatefulSet (with PersistentVolume and PersistentVolumeClaim), and Service.

Application Description

  • Simple shopping list application that allows users to add, mark as purchased, and delete items
  • Each item can have a quantity associated with it
  • All data is stored in PostgreSQL for persistence between application restarts
  • The application uses a Flask web framework with a minimalist interface

Containers

  • simple-web-app: Runs the Python Flask application on port 5000
  • postgres: Runs PostgreSQL database to store shopping list items

Kubernetes Objects

  • Namespace: Isolates all the resources under my-app
  • Deployment (Web App): Manages the stateless web application pods with 2 replicas for high availability
  • Deployment (PostgreSQL): Manages the PostgreSQL database with persistent storage
  • StatefulSet: Manages stateful application pods that require persistent storage
  • PersistentVolume (PV): Provides persistent storage from the host (1GB)
  • PersistentVolumeClaim (PVC): Claims the PV for storage
  • Service (Web App): Exposes the web application externally via LoadBalancer
  • Service (PostgreSQL): Headless service for internal database access

Networking and Storage

  • Internal service discovery allows the web application to connect to PostgreSQL
  • PostgreSQL uses persistent storage to maintain shopping list data even if pods are restarted
  • The web application is exposed externally using a LoadBalancer service

Container Configuration

  • The web app container is based on Python and includes Flask and psycopg2
  • PostgreSQL container uses the official PostgreSQL image
  • Resource limits and readiness probes are configured for better stability

How to Prepare, Run, Pause, and Delete the Application

  1. Prepare the application:

    ./prepare-app.sh
    

    This script builds the Docker image and creates the directory for persistent volume.

  2. Start the application:

    ./start-app.sh
    

    This script creates all necessary Kubernetes objects in the correct order, including PostgreSQL.

  3. Pause or delete the application:

    ./stop-app.sh
    

    This script removes all Kubernetes objects created by start-app.sh.

Accessing the Application

To access the application:

  1. Find the IP address of your Kubernetes node:

    kubectl get nodes -o wide
    
  2. Access the application in your browser at:

    http://<NODE_IP>:80
    

    Where <NODE_IP> is the IP address of any of your Kubernetes nodes.

Application Features

  • Add items with quantity
  • Mark items as purchased/unpurchased
  • Delete items
  • Items list is separated into "to buy" and "purchased" sections
  • Data persists between sessions and application restarts

Database Schema

The application uses a simple PostgreSQL schema:

  • Table: shopping_items
  • Fields:
    • id: Serial primary key
    • item: Text (item name)
    • quantity: Integer (defaults to 1)
    • purchased: Boolean flag (defaults to false)

Troubleshooting

If you encounter issues:

  1. Check pod status:

    kubectl get pods -n my-app
    
  2. View pod logs:

    kubectl logs <pod-name> -n my-app
    
  3. Check service status:

    kubectl get svc -n my-app
    
  4. Check database connectivity:

    kubectl exec -it <web-app-pod-name> -n my-app -- python -c "import psycopg2; conn = psycopg2.connect(host='postgres', dbname='postgres', user='postgres', password='postgres'); print('Connection successful')"