This repository contains a simple 3-layer application deployed in Kubernetes, using Flask for the frontend and backend layers, and PostgreSQL for the database layer.
flowchart LR
user(((user)))
feService((Frontend Service))
subgraph Frontend Layer
fwNode1(Frontend Pod 1 - Flask)
fwNode2(Frontend Pod 2 - Flask)
fwNode3(Frontend Pod 3 - Flask)
end
beService((Backend service))
subgraph Backend Layer
beNode1(Backend Pod 1 - Flask)
beNode2(Backend Pod 2 - Flask)
beNode3(Backend Pod 3 - Flask)
end
dbService((Database service))
subgraph Database Layer
dbNode[(PostgreSQL Pod - Database)]
end
user --> feService
feService --> fwNode1
feService --> fwNode2
feService --> fwNode3
fwNode1 --> beService
fwNode2 --> beService
fwNode3 --> beService
beService --> beNode1
beService --> beNode2
beService --> beNode3
beNode1 --> dbService
beNode2 --> dbService
beNode3 --> dbService
dbService --> dbNode
Before running the application, ensure you have the following installed:
- Docker: To build the container images.
- Kubernetes: To deploy the application using the provided example.yaml file.
- kubectl: The Kubernetes command-line tool to interact with the Kubernetes cluster.
- Clone this repository:
git clone https://github.com/codesimo/k8s-SistemiCloud.git
cd k8s-SistemiCloud
- Build the Docker images for the frontend and backend layers:
docker build -t myfrontend:latest ./frontend
docker build -t mybackend:latest ./backend
- Deploy the application to your Kubernetes cluster:
kubectl apply -f example.yaml
The example.yaml file contains Kubernetes deployment and service configurations for the frontend, backend, and PostgreSQL database layers.
- Accessing the Application
Once the application is successfully deployed, you can access it through the Kubernetes services.
- Frontend: Access the Flask frontend by navigating to
http://<frontend-service-ip>
in your web browser. - Backend: The backend is accessed internally by the frontend service to handle data processing. It is not directly exposed externally.
- PostgreSQL: The PostgreSQL database is not directly accessible from outside the cluster. The backend service interacts with it internally.
To remove the application and associated resources from your Kubernetes cluster, run the following command:
kubectl delete -f example.yaml
Alternatively, you can use the provided run.sh
script, which automates the build and deployment process. Ensure the script has execution permission:
chmod +x run.sh
Then, you can run the application with a single command:
./run.sh
You can customize the application by modifying the Flask frontend and backend code in their respective directories. Additionally, you can adjust the example.yaml file to accommodate specific deployment requirements.