Quick start on GKE with Terraform
The module in deploy/terraform/gcp-gke/ runs the container edition on
Google Cloud:
- a GKE Autopilot cluster with private nodes, or your existing cluster;
- Cloud SQL for PostgreSQL 16 on a private IP, with backups and point-in-time recovery, reached through the Cloud SQL Auth Proxy sidecar with Workload Identity;
- secrets in Secret Manager;
- a GKE Ingress with a reserved static IP, Google-managed certificates and an HTTP-to-HTTPS redirect;
- blobs in PostgreSQL (
blob_store = "postgres", the default) or in a private GCS bucket (blob_store = "gcs").
You need Terraform 1.5.0 or newer, an authenticated gcloud, and a VPC
network and subnetwork.
1. Build and push the image
Section titled “1. Build and push the image”REGION="us-central1"PROJECT="my-gcp-project"IMAGE="$REGION-docker.pkg.dev/$PROJECT/runbook/server:0.1.0"gcloud artifacts repositories create runbook --repository-format=docker \ --location="$REGION" --project="$PROJECT"gcloud auth configure-docker "$REGION-docker.pkg.dev"docker build --platform linux/amd64 -t "$IMAGE" .docker push "$IMAGE"2. Set the variables
Section titled “2. Set the variables”cd deploy/terraform/gcp-gkecp terraform.tfvars.example terraform.tfvarsproject_id = "my-gcp-project"region = "us-central1"network = "default"subnetwork = "default"create_cluster = falsecluster_name = "my-existing-cluster"image = "us-central1-docker.pkg.dev/my-gcp-project/runbook/server:0.1.0"app_domain = "runbooks.example.com"usercontent_domain = "files.example-usercontent.com" # "" if uploads are offauth_methods = "email"smtp_from = "The Runbook <login@example.com>"smtp_url = "smtps://login-user:PASSWORD@smtp.example.com:465"Generated secrets such as the database password end up in the Terraform state, so keep the state in a private, encrypted bucket:
terraform init -backend-config="bucket=my-terraform-state-bucket" \ -backend-config="prefix=runbook/gcp-gke"3. Apply
Section titled “3. Apply”terraform plan -out=tfplanterraform apply tfplanWhen the module creates the cluster (create_cluster = true), apply in two
stages the first time, because the ingress manifests need a reachable
cluster to plan:
terraform apply -target=google_container_cluster.autopilotterraform apply4. Point DNS at the ingress
Section titled “4. Point DNS at the ingress”terraform output ingress_ipCreate A records for app_domain and usercontent_domain pointing at that
address. The managed certificates provision once DNS resolves, usually in 10
to 30 minutes.
5. Create the first owner
Section titled “5. Create the first owner”POD=$(kubectl get pod -n runbook -l app.kubernetes.io/name=runbook -o jsonpath="{.items[0].metadata.name}")kubectl exec -it "$POD" -n runbook -c runbook -- runbook-server bootstrap --owner-email admin@example.comThe owner then signs in with an email code. The module’s README also shows bootstrap as a one-off Job, upgrades and backups.