zkt25/z2/README.md

82 lines
2.8 KiB
Markdown

# PI Visualization Web Application on Kubernetes
## Overview
This project deploys a Python web application using Flask on a Kubernetes cluster. The application displays the first 300 digits of PI with an interactive visualization. The deployment includes a Namespace, Deployment, StatefulSet (with PersistentVolume and PersistentVolumeClaim), and Service.
## Application Description
- The web application visualizes PI digits at the root URL (`/`).
- Each digit appears one at a time (every 0.5 seconds by default) with a unique color.
- Users can control the animation (start, pause, reset) and adjust the speed.
- The application uses one container image built from the Dockerfile provided.
## Containers
- **simple-web-app**: Runs the Python Flask application on port 5000.
## Kubernetes Objects
- **Namespace**: Isolates all the resources under `my-app`.
- **Deployment**: Manages the stateless web application pods with 2 replicas for high availability.
- **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**: Exposes the web application externally via NodePort 30007.
## Networking and Storage
- The application uses Kubernetes networking to enable communication between pods.
- The StatefulSet uses a volume claim template that binds to a PersistentVolume mounted at `/data`.
## Container Configuration
- The container is based on Python and includes Flask.
- It exposes port 5000 to serve the web application.
- Resource limits and readiness probes are configured for better stability.
## How to Prepare, Run, Pause, and Delete the Application
1. **Prepare the application:**
```bash
./prepare-app.sh
```
This script builds the Docker image and creates the directory for persistent volume.
2. **Start the application:**
```bash
./start-app.sh
```
This script creates all necessary Kubernetes objects in the correct order.
3. **Pause or delete the application:**
```bash
./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:
```bash
kubectl get nodes -o wide
```
2. Access the application in your browser at:
```
http://<NODE_IP>:30007
```
Where `<NODE_IP>` is the IP address of any of your Kubernetes nodes.
## Troubleshooting
If you encounter issues:
1. Check pod status:
```bash
kubectl get pods -n my-app
```
2. View pod logs:
```bash
kubectl logs <pod-name> -n my-app
```
3. Check service status:
```bash
kubectl get svc -n my-app
```