This project demonstrates a complete DevOps pipeline for deploying a Python Flask application on Google Cloud Platform (GCP) using Docker, Google Kubernetes Engine (GKE), and Cloud Build.
- Project Overview
- Prerequisites
- Project Structure
- Local Setup and Testing
- GCP Setup
- Deployment Process
- Continuous Integration/Continuous Deployment (CI/CD)
- Monitoring and Maintenance
- Troubleshooting
- Contributing
- License
This project sets up an end-to-end DevOps pipeline that includes:
- A simple Python Flask application
- Containerization using Docker
- Version control with Git and GitHub
- Automated builds using Cloud Build
- Deployment to Google Kubernetes Engine (GKE)
- Load balancing for production-ready setup
The application is a basic "Hello, World!" Flask app that demonstrates the deployment process.
- Google Cloud Platform account
- gcloud CLI installed and configured
- Docker installed locally
- kubectl installed locally
- Python 3.x installed locally
.
├── Dockerfile
├── app.py
├── cloudbuild.yaml
├── deployment.yaml
├── requirements.txt
└── README.md
app.py
: The main Flask applicationDockerfile
: Instructions for building the Docker imagecloudbuild.yaml
: Configuration for Cloud Builddeployment.yaml
: Kubernetes deployment configurationrequirements.txt
: Python dependencies
-
Clone the repository:
git clone https://github.com/deepakkapse/gcp-devops-project.git cd gcp-devops-project
-
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Run the Flask app locally:
python app.py
Visit
http://localhost:5000
in your browser to see the app running. -
Build and run the Docker container locally:
docker build -t flask-app:v1 . docker run -p 5000:5000 flask-app:v1
Again, visit
http://localhost:5000
to verify the containerized app is working.
-
Create a new GCP project or select an existing one.
-
Enable the following APIs:
- Cloud Build API
- Container Registry API
- Kubernetes Engine API
-
Create a GKE cluster:
gcloud container clusters create flask-cluster --num-nodes=2 --zone=us-central1-a
-
Configure kubectl to use your GKE cluster:
gcloud container clusters get-credentials flask-cluster --zone=us-central1-a
-
Push your code to GitHub.
-
Set up a Cloud Build trigger:
- Go to Cloud Build > Triggers
- Connect your GitHub repository
- Create a new trigger that activates on pushes to the main branch
-
The
cloudbuild.yaml
file will instruct Cloud Build to:- Build the Docker image
- Push the image to Container Registry
- Deploy the application to GKE
-
After the build completes, you can check your deployment:
kubectl get deployments kubectl get services
-
Get the external IP of your service and visit it in a browser to see your deployed app.
The CI/CD pipeline is set up as follows:
- Developer pushes code to GitHub
- Cloud Build trigger activates
- Cloud Build builds Docker image and pushes to Container Registry
- Cloud Build deploys the new image to GKE
- Kubernetes rolls out the new version of the application
This process ensures that every push to the main branch results in an automated deployment of the latest version of your application.
- Use Google Cloud Console to monitor your GKE cluster and deployments
- Set up logging and monitoring in GCP to track application performance
- Regularly update your dependencies and Docker base image for security
- Check Cloud Build logs for build and deployment issues
- Use
kubectl logs
andkubectl describe
for debugging Kubernetes issues - Ensure all required APIs are enabled in your GCP project
Contributions to this project are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.