This repository contains the necessary files and instructions to deploy a FastAPI application on Google Kubernetes Engine (GKE). Before proceeding with the deployment, make sure you have set up an Artifact Registry repository to store your container image.
Before proceeding with the deployment, ensure that you have the following prerequisites:
- Google Cloud SDK installed and configured.
- Docker installed on your local machine.
-
Authenticate with Google Cloud:
gcloud auth login -
Set the project ID:
gcloud config set project test-390300 -
Build the Docker image:
docker build -t fastapi-gke-image . -
Submit the Docker image to the Artifact Registry repository:
gcloud builds submit --tag us-west1-docker.pkg.dev/test-390300/testapp/fastapi-gke-image -
Create a GKE cluster:
gcloud container clusters create fastapi-gke-cluster --zone us-central1-a --num-nodes 3 -
Apply the deployment configuration:
kubectl apply -f deployment.yaml -
Expose the deployment as a service:
kubectl expose deployment testapp-deployment --type LoadBalancer --port 80 --target-port 8080 -
Retrieve the service details:
kubectl get services
To delete the deployment and the service, use the following commands:
kubectl delete deployment testapp-deployment
kubectl delete service testapp-deployment
Make sure to run these commands when you no longer need the deployed application.
For additional information and troubleshooting, refer to the official documentation provided by Google Cloud and Kubernetes.
Note: Before starting the deployment process, make sure you have set up an Artifact Registry repository to store your container image. This repository will serve as the source for your Docker image during the deployment process.
Enjoy your FastAPI application on GKE!