This project deploys a simple Python Flask application to Google Kubernetes Engine (GKE) using Google Cloud Build and Google Artifact Registry. The application is exposed through an endpoint, allowing easy access.
app.py
: Contains the Python Flask application code.requirements.txt
: Lists the dependencies required for the Flask application.Dockerfile
: Defines the Docker image build instructions.cloudbuild.yaml
: Configures the Google Cloud Build steps for building and deploying the Docker image.gke.yaml
: Specifies the Kubernetes deployment and service configurations for GKE.
To run this project locally or deploy it to GKE, follow these steps:
-
Clone the repository:
git clone https://github.com/guddev99/gcp-devops-project.git
-
Navigate to the project directory:
cd gcp-devops-project
-
Ensure you have Docker installed:
-
Build the Docker image locally:
docker build -t gcpdevops .
-
Run the Docker container locally:
docker run -p 5000:5000 gcpdevops
Access the Flask application at
http://localhost:5000
in your web browser. -
To deploy to GKE, ensure you have a GKE cluster set up and configured. Create a new namespace:
# Create a new namespace to isolate the deployment kubectl create namespace <namespace-name>
Note: Creating a new namespace helps isolate the deployment within your Kubernetes cluster, ensuring better organization and management of resources.
-
Update
cloudbuild.yaml
andgke.yaml
with your GKE cluster details. -
Set up a Cloud Build Trigger connected with the project repository. This trigger should be configured to listen for pushes to the main/master branch.
-
Connect your project repository with Cloud Build by following the instructions provided in the Connecting to source repositories section of the Cloud Build documentation.
-
Once your repository is connected, create a Cloud Build Trigger following the Creating a build trigger section of the Cloud Build documentation.
-
You can refer to the screenshots provided, which were taken from the GCP console during the setup process.
-
-
When changes are pushed to this branch, Cloud Build will automatically build the Docker image, push it to Google Artifact Registry, and deploy it to GKE.
-
Access your deployed application through the endpoint provided by the GKE service.
- Google Cloud Build Documentation
- Google Artifact Registry Documentation
- Google Kubernetes Engine Documentation
Feel free to contribute to this project or customize it according to your requirements!