Skip to content

davmano/flask-jenkins-aut-app

Repository files navigation

🧪 Flask Jenkins CI/CD Pipeline

This project demonstrates a complete CI/CD pipeline for deploying a simple Flask web application using:

  • 🐳 Docker
  • 🔧 Jenkins
  • ☸️ Kubernetes (via Minikube)
  • ☁️ Docker Hub

GitHub Repo ➡️ flask-jenkins-aut-app


🔍 Project Overview

The pipeline performs the following automated steps:

  1. Clones the Flask app from GitHub.
  2. Builds a Docker image of the Flask app.
  3. Runs and tests the container to ensure the app is healthy.
  4. Pushes the image to Docker Hub.
  5. Deploys the updated image to a Kubernetes cluster running locally with Minikube.

🛠️ Tech Stack

Component Tool/Service Used
Language Python (Flask)
CI/CD Jenkins
Containerization Docker
Container Registry Docker Hub
Orchestration Kubernetes (Minikube)

🔧 Pipeline Stages (Jenkinsfile)

1. Checkout Source

  • Pulls code from GitHub repo.

2. Build Docker Image

docker build -t flask-app .
  • Builds the app using a Dockerfile based on python:3."latest-slim.

3. Run and Test Container

docker run -d --name flask-app-test -p 5000:5000 flask-app
curl -f http://localhost:5000
  • Confirms the app starts and responds properly.

4. Push to Docker Hub

docker tag flask-app:latest davmano/flask-app:latest
docker login -u davmano -p $DOCKER_HUB_PASSWORD
docker push davmano/flask-app:latest
  • Pushes the tested image to Docker Hub.

5. Deploy to Kubernetes

kubectl config use-context minikube
kubectl set image deployment/flask-app flask-app=davmano/flask-app:latest --record
  • Updates the Kubernetes deployment with the latest Docker image.

🧱 Key Configuration Steps

  • Jenkins has Docker installed and is added to the docker group.
  • Minikube is running locally and accessible via Jenkins.
  • Jenkins has read access to Kubernetes kubeconfig and certs.
sudo mkdir -p /var/lib/jenkins/.kube
sudo cp ~/.kube/config /var/lib/jenkins/.kube/config
sudo chown -R jenkins:jenkins /var/lib/jenkins/.kube

Start Jenkins normally (your command is fine):

docker run -d \
  --name jenkins \
  -p 8080:8080 -p 50000:50000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v jenkins_home:/var/jenkins_home \
  jenkins/jenkins:lts

Then exec into the container as root to install Docker CLI:

docker exec -it --user root jenkins bash

Inside the container run:

apt-get update
apt-get install -y docker.io
exit


🔐 Credentials

  • Docker Hub credentials stored in Jenkins using withCredentials.
  • Kubeconfig manually made accessible to Jenkins user.

🧠 Learning Highlights

  • Built a real-world CI/CD pipeline from scratch.
  • Understood Docker image creation, tagging, and container testing.
  • Deployed containers into Kubernetes using command-line tools.
  • Managed Jenkins security, permissions, and pipeline scripting.

🚀 Next Steps

  • Replace kubectl set image with YAML-based kubectl apply -f.
  • Add automated rollback and rollout status checks.
  • Integrate with GitHub webhooks for auto-triggering builds.
  • Implement Slack/email notifications.

📸 Screenshot

pipeline-screenshot

k8s-screenshot


👨‍💻 Author

David Mano DevOps Engineer | Cloud Enthusiast | CI/CD Practitioner


📂 License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published