Skip to content

codesimo/k8s-SistemiCloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample 3-Layer Application in Kubernetes

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
Loading

Prerequisites

Before running the application, ensure you have the following installed:

  1. Docker: To build the container images.
  2. Kubernetes: To deploy the application using the provided example.yaml file.
  3. kubectl: The Kubernetes command-line tool to interact with the Kubernetes cluster.

Getting Started

  1. Clone this repository:
git clone https://github.com/codesimo/k8s-SistemiCloud.git
cd k8s-SistemiCloud
  1. Build the Docker images for the frontend and backend layers:
docker build -t myfrontend:latest ./frontend
docker build -t mybackend:latest ./backend
  1. 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.

  1. 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.

Cleaning Up

To remove the application and associated resources from your Kubernetes cluster, run the following command:

kubectl delete -f example.yaml

run.sh

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

Customization

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.