A simple web application show current time using flask
.
├── ansible
│ ├── ansible.cfg
│ ├── hosts.ini
│ └── site.yml
├── docker-compose.yml
├── Dockerfile
├── .github
│ └── workflows
│ ├── action.yml
│ └── pytest.yml
├── Helm
│ └── mychart
│ ├── Chart.yaml
│ ├── templates
│ │ ├── deployment.yaml
│ │ └── service.yaml
│ └── values.yaml
├── Jenkinsfile
├── Kubernetes
│ ├── deployment.yaml
│ ├── ingress.yaml
│ ├── limits.yaml
│ ├── namespace.yaml
│ ├── pod.yaml
│ └── service.yaml
├── monitoring
│ ├── config
│ │ ├── loki-config.yaml
│ │ ├── prometheus-config.yaml
│ │ └── promtail-config.yaml
│ └── docker-compose.yaml
├── nginx.conf
├── ReadMe.md
├── requirements.txt
├── static
│ └── clockimage.jpg
├── task.py
├── templates
│ └── index.html
├── Terraform
│ └── main.tf
└── test_task.py
-
ansible/: Contains Ansible configuration and playbooks for deploying and managing infrastructure.-
ansible.cfg:Configuration file for Ansible. -
hosts.ini: Inventory file listing the hosts managed by Ansible. -
site.yml:Ansible playbook for deploying and managing the application
-
-
docker-compose.yml: Docker Compose configuration file. -
Dockerfile: Dockerfile for building the Flask application image. -
.github/workflows/: GitHub Actions workflow configurations for CI/CD.-
action.yml: Action for automating tasks. -
pytest.yml: Pytest configuration for testing.
-
-
Helm/mychart/: Contains Helm chart for managing Kubernetes deployments.-
Chart.yaml: Metadata for the Helm chart. -
templates/: Kubernetes resource templates for deployment and service.deployment.yaml: Template for deploying the application.service.yaml: Template for defining the service.
-
values.yaml: Default configuration values for the Helm chart.
-
-
Jenkinsfile:The Jenkins pipeline for continuous integration and delivery (CI/CD). -
Kubernetes/: Contains Kubernetes manifests for deploying and managing resources in a Kubernetes cluster.-
deployment.yml: Deployment configuration for the application. -
ingress.yml: Ingress rules for managing external access to the services. -
limits.yml: Resource limits and requests for Kubernetes pods. -
namespace.yml: Kubernetes namespace configuration. -
pod.yml: Pod configuration for the application. -
service.yml: Service configuration for exposing the application.
-
-
monitoring/: Contains configurations for monitoring using Prometheus, Loki, and Promtail.-
config/:-
loki-config.yaml: Configuration for Loki. -
prometheus-config.yaml: Configuration for Prometheus. -
promtail-config.yaml: Configuration for Promtail.
-
-
docker-compose.yml: file defines all the services needed for the monitoring stack.
-
-
nginx.conf: Nginx configuration file. -
ReadMe.md: Markdown file providing project information (Project documentation.). -
requirements.txt: List of Python dependencies for the Flask application. -
static/:Directory containing Image for the Flask application -
task.py: Main Python file containing the Flask application code. -
templates/: Directory containing HTML templates for the Flask application.index.html: HTML template for displaying the current time.
-
Terraform/: Contains Terraform configurations for infrastructure provisioning.main.tf: Main Terraform configuration file.
-
test_task.py: Python script with tests for the Flask application.
Before running the application, ensure you have the following installed:
- Python 3.11
- Flask 2.0.2 (install via pip install Flask)
- Docker
- Jenkins
- Ansible
- Terraform
- minikube
- kubectl
- Helm
To get started with the Flask Application, follow these steps:
-
install python in your machine
sudo apt update sudo apt install python3.11
-
check if python is installed
python3 --version
-
create virtualenv
sudo apt install python3.11-venv python3 -m venv venv
-
activate virtualenv
source venv/bin/activate -
install Docker
sudo apt-get update sudo apt install docker.io docker-compose docker-buildx # Test docker sudo groupadd docker docker run hello-world -
install ansible
sudo apt update sudo apt install ansible ansible-galaxy collection install community.docker
-
install terraform
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform
-
Install minikube
# Install on linux curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64 # start your cluster minikube start # check version minikube version ## Result ## minikube version: v1.34.0 commit: 210b148df93a80eb872ecbeb7e35281b3c582c61
-
Install kubectl
# Install on linux curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256" echo "$(cat kubectl.sha256) kubectl" | sha256sum --check sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl # check version kubectl version --client ## Result ## Client Version: v1.31.0 Kustomize Version: v5.4.2
-
Install Helm:
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- install flask
pip install Flask
- install required packages listed
pip install -r requirements.txt
- install Jenkins
sudo apt update sudo apt upgrade sudo apt install openjdk-17-jre wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - # Test java installed java --version sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt update sudo apt install jenkins # test jenkins insalled jenkins --version
- Run the test to ensure functions work correctly
python test_task.py
- Run the application
python3 task.py
The application will be accessible at The application will be accessible a http://127.0.0.1:5000
docker build -t shahdelnassag/dev-task . docker run -p5000:5000 shahdelnassag/dev-taskThe application will be accessible at http://127.0.0.1:5000
link Image: DockerHub
docker-compose up --buildThe app will running on : http://127.0.0.1:5000 OR http://172.18.0.2:5000
This pipeline ensures that your application is built, packaged into a Docker container, and then deployed, allowing continuous integration and delivery.
-
Create AWS account & Sign In
https://aws.amazon.com/
-
Create EC2 instence
-
Security Groups Rules
1. SSH : 22 2. HTTP: 80 3. Custom rule: 8080 -
Create Key_Pair
Download the .pem file
-
Connect SSH client:
sudo chmod 400 ./labsuser.pem ssh -i ./labsuser.pem ubuntu@ec2-3-87-37-229.compute-1.amazonaws.com
-
Run Jenkins on :
ec2-3-87-37-229.compute-1.amazonaws.com:8080
-
Run command to get password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
Create a job
- Run file (site.yml)
ansible-playbook -i hosts.ini site.yml-
Create instance using terraform
cd Terraform terraform init terraform plan terraform apply -
Connect to instance
cd ansible sudo chmod 400 ./labsuser.pem ssh -i ./labsuser.pem ubuntu@ec2-3-88-11-121.compute-1.amazonaws.com -
Run an ansible playbook (EC2 instance):
ansible-playbook -i hosts.ini site.yml
-
Run app against EC2 instance Link ---> http://ec2-18-207-161-212.compute-1.amazonaws.com/
-
Start Minkube:
# Ensure Docker Running sudo systemctl start docker # start minikube minikube start
-
Create the namespace:
kubectl apply -f namespace.yaml- Apply the LimitRange:
kubectl apply -f limits.yaml- Deploy the application:
kubectl apply -f deployment.yaml- Create the service:
kubectl apply -f service.yaml- Set up ingress:
kubectl apply -f ingress.yaml minikube service time-svc Run app on link --> http://192.168.49.2:30090
kubectl delete all --all -n time-nsp-
Create helm chart
helm create mychart
-
Deploy helm chart
# First Deploying helm install timeapplication mychart --namespace time-nsp # Upgrade the Release helm upgrade timeapplication mychart --namespace time-nsp
-
Check the Updated Services:
kubectl get services -n time-nsp ## Result ## # NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE # timeapplication-svc NodePort 10.103.128.202 <none> 5000:30091/TCP 3m35s
-
Access the application via ---> http://192.168.49.2:30091
minikube service timeaaplication-svc -n time-nsp
-
Run prometheus on --->
localhost:9090 -
Check the status of running the app on --->
localhost:9090/targets?search= -
Run grafana on --->
localhost:3000 -
Run Application on -->
localhost:8081
docker compose down












