This project is a simple Flask web application containerized using Docker and deployed on Google Kubernetes Engine (GKE). Initially, the project aimed for deployment on OpenShift, but due to trial limitations and troubleshooting challenges, it was transitioned to GKE. This document details the process, challenges, and solutions encountered during the deployment.
- Built with Flask (Python web framework)
- Containerized with Docker
- Deployed on Google Kubernetes Engine (GKE)
- Supports local development with Docker
Ensure you have the following installed:
- Python 3.9+
- Docker
- Google Cloud SDK (gcloud)
- kubectl (Kubernetes command-line tool)
-
Clone the repository:
git clone [https://github.com/ELew-Dev/flask-web-app.git](https://github.com/ELew-Dev/flask-web-app.git) cd flask-web-app -
Build the Docker image:
docker build -t flask-web-app . -
Run the container:
docker run -p 5000:5000 flask-web-app
-
Open your browser and go to:
http://localhost:5000
-
Create a GKE Cluster:
- In the Google Cloud Console, navigate to Kubernetes Engine and create a GKE Autopilot cluster.
-
Authenticate Docker with GCP:
gcloud auth configure-docker
-
Build and Push the Docker Image:
docker build -t gcr.io/YOUR_PROJECT_ID/flask-web-app . docker push gcr.io/YOUR_PROJECT_ID/flask-web-app- Replace
YOUR_PROJECT_IDwith your Google Cloud Project ID.
- Replace
-
Configure Kubernetes Manifests:
- Ensure you have
deployment.yamlandservice.yamlfiles. - Update the
deployment.yamlfile with the correct image path (gcr.io/YOUR_PROJECT_ID/flask-web-app).
- Ensure you have
-
Deploy the Application:
kubectl apply -f deployment.yaml kubectl apply -f service.yaml
-
Expose the Application:
-
The
service.yamluses a LoadBalancer, which will provide an external IP. -
Get the external IP:
kubectl get service flask-app-service
-
Access the application in your browser using the external IP.
-
(Include the entire detailed development log you provided here)
To avoid incurring costs:
- Delete the GKE cluster.
- Delete the Docker image from Google Cloud Registry (GCR) or Artifact Registry.
- Consider deleting the Google Cloud Project if it is no longer needed.
- Implement authentication.
- Add database support.
- Improve error handling.
- Set up CI/CD pipeline.
- Configure HTTPS.
- Add a custom domain.
- Google Cloud Platform (GCP) has its own authentication and authorization mechanisms.
- Managing the PATH environment variable is crucial for GCP CLI tools.
- GKE Autopilot simplifies cluster management but has unique behaviors.
- Google Cloud-specific commands are necessary for authentication, deployment, and image storage.
- Artifact Registry is the newer method for storing Docker images on GCP.