This project demonstrates how to deploy a simple python project (in this case a FAST API project) to GKE using Cloud Build and using Ansible to Provision a GKE cluster.
Cloud build is configured with a trigger to auto deploy the project when a commit is pushed to the main
branch.
Provision a cluster, specified as prod-cluster
- Ansible
- GCP Ansible Collection
- Obtain a GCP default Compute Engine service account file(usually
.json
) and place it at the root folder of the project - Obtain the Google Project ID
- Ensure all the requirents are isntalled in the virtual environment
$ pip install -r requirements.txt"
- Run the playbook with the following option to provide for the google project id
$ ansible-playbook -e project_name=<GCP_PROJECT_ID> ansible/playbook.yml
- Ensure all requirements are in the local environemt
$ pip install -r requirements.txt"
- Run the API in dev mode
$ uvicorn main:app --reload
- Navigate to
http://127.0.0.1:8000/docs
to read the API docs - A simple TODO list can be found in
http://127.0.0.1:8000/todo/fe
```
$ gcloud builds submit --substitutions=SHORT_SHA=<GIT_COMMIT_SHORT_SHA>,_CLOUDSDK_CONTAINER_CLUSTER=<GCP_CLUSTER_NAME>,_CLOUDSDK_COMPUTE_ZONE="CLUSTER_LOCATION"
```
- Joseph M Kyalo