The Weather App is a simple Flask-based web application designed to provide users with a 7-day weather forecast for any city. This project emphasizes DevOps practices with automated infrastructure provisioning, CI/CD pipelines, and Kubernetes deployment on AWS EKS.
- Self-Hosted GitLab: For Source Control Management (SCM).
- Jenkins: For building and deploying the application with CI/CD pipelines.
- Terraform: For provisioning infrastructure as code.
- AWS (Amazon Web Services): As the cloud provider.
- EKS (Elastic Kubernetes Service): For managing containerized applications.
- DockerHub: As the container registry to store and manage Docker images.
- Prerequisites
- Installation and Setup
- Usage
- Infrastructure as Code (IaC) Details
- Continuous Integration/Continuous Deployment (CI/CD) Pipeline
- Kubernetes Deployment
- Configuration
- Testing
- Contact Information
- Acknowledgments
- Python: Version 3.11+
- Docker: Installed and running
- Kubernetes:
kubectlconfigured for your cluster - AWS CLI: Configured with appropriate access keys
- Terraform: Installed on your local machine
- Jenkins: Installed with Docker and Kubernetes plugins
-
Clone the repository:
git clone <repository-url> cd weather-app
-
Set up a virtual environment:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt -
Run the application locally:
python src/app.py
-
Access the app at
http://127.0.0.1:5000.
-
Build the Docker image:
docker build -t your-dockerhub-username/weather-app:latest . -
Run the Docker container:
docker run -d -p 5000:5000 your-dockerhub-username/weather-app:latest
- Open the application in your browser.
- Enter a city name in the search bar to fetch the 7-day weather forecast.
- View day/night temperatures and humidity levels for the selected city.
- Cloud Provider: AWS
- Services Used:
- EKS for Kubernetes cluster
- VPC with subnets and NAT gateways
- Terraform: Used to provision the infrastructure.
-
Navigate to the Terraform directory:
cd terraform -
Initialize and apply Terraform:
terraform init terraform apply
-
Configure
kubectlto connect to the EKS cluster:aws eks update-kubeconfig --region <AWS_REGION> --name <CLUSTER_NAME>
I use two separate Jenkinsfiles, one for the Build Pipeline (build.Jenkinsfile) and another for the Deploy Pipeline (deploy.Jenkinsfile), which offers several benefits:
Separation of Concerns: Each file handles a distinct part of the pipeline: the build pipeline focuses on testing, building, and packaging the application, while the deploy pipeline manages the deployment process. This modular approach makes pipelines easier to manage and debug.
Flexibility: Separate Jenkinsfiles allow you to trigger the deploy pipeline independently of the build pipeline, enabling faster iterations and re-deployments without rebuilding the application.
- Stages:
- Cleanup
- Install Requirements
- Pylint Test
- Docker Build
- Smoke Test
- Tag and Push to DockerHub
- Trigger Deploy Pipeline
- Stages:
- Cleanup
- Deploy to EKS
- Deploys 2 replicas of the Weather App container.
- Exposes the app on a NodePort (port 5000).
-
Apply Kubernetes manifests:
kubectl apply -f k8s-manifest/deployment.yaml kubectl apply -f k8s-manifest/service.yaml
-
Verify deployment:
kubectl get pods -n weather-app kubectl get svc -n weather-app
APP_NAME: Application nameREGISTRY_URL: DockerHub registry URLAWS_REGION: AWS region for deploymentKUBECONFIG_CREDENTIALS_ID: Jenkins credentials ID for Kubernetes config
- Terraform:
main.tf,vpc.tf,eks-cluster.tf: Define AWS infrastructure.
- Jenkinsfiles:
build.Jenkinsfile,deploy.Jenkinsfile: Define CI/CD pipelines.
-
Run Pylint for static code analysis:
pylint src/*.py -
Run Python unit tests:
python -m unittest discover src/tests
- Test app connectivity:
python src/tests/check-connectivity.py
- Ensure Selenium WebDriver is installed.
- Run:
python src/tests/test-selenium.py
- Maintainer: Matan Kaufman
- Email: matankaufman1@gmail.com
- OpenMeteo API: For weather data
- Terraform AWS Modules: For infrastructure setup
- Jenkins Community: For CI/CD support