This project facilitates the automated creation of a Kubernetes cluster on Google Cloud Platform (GCP) using Terraform and deploys a FastAPI application using Helm.
-
Google Cloud SDK: You must have the Google Cloud SDK installed and configured with appropriate permissions.
-
Terraform: Terraform version 0.13 or newer must be installed.
-
kubectl: Kubernetes command-line tool, kubectl, must be installed.
-
Helm: Helm version 3 or newer must be installed.
-
Docker: If you want to build the container image locally, you will need Docker installed. Code can be found here
Ensure you have the appropriate permissions and set the necessary environment variables:
gcloud auth login
gcloud auth application-default login
Navigate to the vars directory then copy and update the tfvars file
cd vars
cp example.tfvars dev.tfvars
Navigate to the Terraform directory and run the following commands to initialise and create the cluster:
cd ../terraform
terraform init
terraform apply -var-file=../vars/dev.tfvars
By following these commands, Terraform will initialse the configuration within the directory and apply the defined plan. It will create a Kubernetes cluster on Google Cloud Platform using the specifications defined in your Terraform files. Ensure that the variables within the Terraform vars files are properly set up to match your desired cluster configuration.
Make sure your Kubernetes cluster is configured as the current context for kubectl, then navigate to the Helm chart directory, copy and update the helm values to match your configuration (Redis IP, SQL IP, etc).
cd ../helm/charts/
cp values.yaml.example values.yaml
Deploy the FastAPI application using Helm:
helm install firney-workshop .
Your FastAPI application will be available at the load balancer's IP address, which you can find using.
kubectl get ingress -n workshop
If you would like to test your new api you can downlaod our postman collection here
You can customise various parameters of both the Kubernetes cluster and the FastAPI application by modifying the respective Terraform and Helm configuration files.
To destroy the created resources:
helm uninstall firney-workshop
cd ../../terraform
terraform destroy -var-file=../vars/dev.tfvars