https://github.com/jbn1995/two-tier-application
This repository contains a two-tier Flask application with a MySQL database backend, deployed on Kubernetes using Helm. The application is designed to demonstrate how to deploy and manage a web service with a MySQL database in a Kubernetes environment, utilizing Helm for easy package management.
https://github.com/jbn1995/two-tier-application
docker docker-compose eks-cluster helm kubernetes
Last synced: about 1 year ago
JSON representation
This repository contains a two-tier Flask application with a MySQL database backend, deployed on Kubernetes using Helm. The application is designed to demonstrate how to deploy and manage a web service with a MySQL database in a Kubernetes environment, utilizing Helm for easy package management.
- Host: GitHub
- URL: https://github.com/jbn1995/two-tier-application
- Owner: jbn1995
- License: mit
- Created: 2024-10-16T10:19:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-26T16:53:47.000Z (over 1 year ago)
- Last Synced: 2025-02-14T12:35:50.661Z (over 1 year ago)
- Topics: docker, docker-compose, eks-cluster, helm, kubernetes
- Language: HTML
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Flask App with MySQL
This is a simple Flask app that interacts with a MySQL database. The app allows users to submit messages, which are then stored in the database and displayed on the frontend.
# Notes
```
- There is also a separate instruction-file in each of K8s-manifests and eks-manifests repository.
- You can deploy this application in Kind-cluster (A cluster where kubernetes run as a docker containers)
- Make sure you read before deploy the applications on Kubernetes(EKS,Kubeadm/Minikube).
- Also You can Deploy the Two-Tier Flask Application on Kubernetes using Helm.
```
# Docker Setup
# Prerequisits
Before you begin, make sure you have the following installed:
- Docker
- Git (optional, for cloning the repository)
## Setup
1. Clone this repository (if you haven't already):
```bash
git clone https://github.com/jbn1995/Two-Tier-Application.git
```
2. Navigate to the project directory:
3. Create a `.env` file in the project directory to store your MySQL environment variables:
```bash
touch .env
```
4. Open the `.env` file and add your MySQL configuration:
```
MYSQL_HOST=mysql
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DB=your_database
```
## Usage
1. Start the containers using Docker Compose:
```bash
docker-compose up --build
```
2. Access the Flask app in your web browser:
- Frontend: http://localhost
- Backend: http://localhost:5000
3. Create the `messages` table in your MySQL database:
- Use a MySQL client or tool (e.g., phpMyAdmin) to execute the following SQL commands:
```sql
CREATE TABLE messages (
id INT AUTO_INCREMENT PRIMARY KEY,
message TEXT
);
```
4. Interact with the app:
- Visit http://localhost to see the frontend. You can submit new messages using the form.
- Visit http://localhost:5000/insert_sql to insert a message directly into the `messages` table via an SQL query.
## Cleaning Up
To stop and remove the Docker containers, press `Ctrl+C` in the terminal where the containers are running, or use the following command:
```bash
docker-compose down
```
## To run this two-tier application using without docker-compose
- First create a docker image from Dockerfile
```bash
docker build -t flaskapp .
```
- Now, make sure that you have created a network using following command
```bash
docker network create
```
- Attach both the containers in the same network, so that they can communicate with each other
i) MySQL container
```bash
docker run -d \
--name mysql \
-v mysql-data:/var/lib/mysql \
--network= \
-e MYSQL_DATABASE=mydb \
-e MYSQL_ROOT_PASSWORD=admin \
-p 3306:3306 \
mysql:5.7
```
ii) Backend container
```bash
docker run -d \
--name flaskapp \
--network= \
-e MYSQL_HOST=mysql \
-e MYSQL_USER=root \
-e MYSQL_PASSWORD=admin \
-e MYSQL_DB=mydb \
-p 5000:5000 \
flaskapp:latest
```
## Notes
- Make sure to replace placeholders (e.g., `your_username`, `your_password`, `your_database`) with your actual MySQL configuration.
- This is a basic setup for demonstration purposes. In a production environment, you should follow best practices for security and performance.
- Be cautious when executing SQL queries directly. Validate and sanitize user inputs to prevent vulnerabilities like SQL injection.
- If you encounter issues, check Docker logs and error messages for troubleshooting.
```