This example project demonstrates how to use Garden to spin up a GKE cluster and a Cloud SQL database via Garden's Terraform plugin.
The example was made to accompany this guide. And here's video a that shows the entire workflow:
See here for a detailed step-by-step guide.
You need to have Garden installed to use this project.
If you haven't already, follow the instructions here to install the gcloud
tool, and authenticate with GCP:
gcloud auth application-default login
Choose a project ID for the demo project and run the following (skip individual steps as appropriate):
export PROJECT_ID=<id>
# (Skip if you already have a project)
gcloud projects create $PROJECT_ID
# If you haven't already, enable billing for the project (required for the APIs below).
# You need an account ID (of the form 0X0X0X-0X0X0X-0X0X0X) to use for billing.
gcloud alpha billing projects link $PROJECT_ID --billing-account=<account ID>
# Enable the required APIs (this can sometimes take a while).
gcloud services enable compute.googleapis.com container.googleapis.com servicemanagement.googleapis.com servicenetworking.googleapis.com --project $PROJECT_ID
Set you're own GCP project ID in the project level garden.yml
:
variables:
gcp_project_id: my-gcp-project # <--- Replace this with your GCP project ID
gcp_region: europe-west1 # <--- And optionally this...
gcp_zone: europe-west1-b # <--- ... and this
Install the cluster-wide services Garden needs by running:
garden plugins kubernetes cluster-init
This will take a while because the cluster needs to be provisioned, and some services installed when it's ready.
The project has two environments configured:
- a development environment that uses a Postgres Helm chart for the database
- a staging environment where Garden provisions a Cloud SQL database
Deploy to dev
with:
garden deploy
and to staging
with:
garden deploy --env staging
Simply delete your GCP project, and the Terraform state:
gcloud projects delete $PROJECT_ID
rm -rf .terraform terraform.tfstate