diff --git a/z2/README.md b/z2/README.md index 2b2ae9c..67d7d41 100644 --- a/z2/README.md +++ b/z2/README.md @@ -1,38 +1,91 @@ -# Web Application Deployment to Kubernetes +# Todo App Kubernetes Deployment + +This repository contains the Kubernetes configuration files to deploy my Todo App. ## Description -This project deploys a simple web application to Kubernetes using a Deployment, StatefulSet, Service, PersistentVolume, and PersistentVolumeClaim. The application is a basic Node.js server that serves a web page. +The Todo App is a web application for creating, reading, updating, and deleting tasks. It is built using Node.js and is containerized using Docker. The application uses a PostgreSQL database to store task data. ## Containers Used -- **web-app-container**: A container running a Node.js application. +- **elineen/todo-app:latest**: The main application container that runs the Todo App. +- **postgres:latest**: The container that runs the PostgreSQL database. ## Kubernetes Objects -- **Namespace**: `my-namespace` -- **Deployment**: `web-app-deployment` -- **StatefulSet**: `web-app-statefulset` -- **Service**: `web-app-service` -- **PersistentVolume**: `pv-volume` -- **PersistentVolumeClaim**: `pvc-claim` +- **Namespace**: `namespace.yaml` - The namespace in which all other objects are created. +- **Deployment**: `deployment.yaml` - Defines the deployment configuration for the Todo App. +- **StatefulSet**: `statefulset.yaml` - Defines the stateful set configuration for the Todo App, including PersistentVolume and PersistentVolumeClaim objects. +- **Service**: `service.yaml` - Exposes the Todo App to the network. +- **Database Deployment**: `db-deployment.yaml` - Defines the deployment configuration for the PostgreSQL database. +- **Database Service**: `db-service.yaml` - Exposes the PostgreSQL database to the network within the cluster. ## Virtual Networks and Named Volumes -- The application uses a PersistentVolume and PersistentVolumeClaim to store data. -- The Service exposes the application on port 80. +- **PersistentVolume**: Defines a persistent volume for storing application data. +- **PersistentVolumeClaim**: Claims the persistent volume for use by the StatefulSet. +- **Database PersistentVolume**: Defines a persistent volume for storing database data. +- **Database PersistentVolumeClaim**: Claims the persistent volume for use by the PostgreSQL database. ## Container Configuration -- The Dockerfile builds a Node.js application and exposes port 8080. -- The Deployment and StatefulSet use the image `my-web-app:latest`. +The container configuration includes the following: +- **Application Image**: `elineen/todo-app:latest` +- **Database Image**: `postgres:latest` +- **Ports**: The application listens on port 8080. The PostgreSQL database listens on port 5432. +- **Volume Mounts**: The application container mounts the persistent volume at `/data`. The PostgreSQL container mounts the persistent volume at the default data directory. + +## Database Configuration +The application uses a PostgreSQL database to store task data. The database is configured with the following environment variables: + +- **POSTGRES_DB**: mydatabase +- **POSTGRES_USER**: myuser +- **POSTGRES_PASSWORD**: mypassword ## Instructions +### Prerequisites + +- Kubernetes cluster (e.g., Minikube, Docker Desktop, or a cloud provider like GKE, EKS, AKS) +- `kubectl` command-line tool installed and configured to interact with your Kubernetes cluster +- Docker installed and configured to pull images from Docker Hub + ### Prepare the Application -1. Run the `prepare-app.sh` script to build the Docker image and create the namespace and persistent volumes. +Run the following script to prepare the application, build the Docker image, and create the persistent volumes: ```bash ./prepare-app.sh +``` +### Start the Application +Run the following script to create all Kubernetes objects and start the application: + +``` +./start-app.sh +``` +### View the Application + +If you are using a LoadBalancer service, you can access the application using the external IP address provided by the service. Run the following command to get the service details: + +``` +kubectl get services -n my-namespace +``` +Open a web browser, enter this sentence and replace with the external IP address obtained from the previous step. + +``` +http:// +``` +Another way can also be by using Minikube: +``` +minikube service web-app-service -n my-namespace +``` +### Stop the Application + +Run the following script to delete all created Kubernetes objects and stop the application: + +```bash +./stop-app.sh +``` + +This is it, your Todo-List is working, enjoy! \ No newline at end of file