gke-terraform-example
gke-terraform-example copied to clipboard
Backend service creation ambigious
Great work! I'm setting up something similar, and I have a question about your setup.
The command gcloud compute backend-services list
is used to get the backend service, however, it's very unclear where this gets created. There's a separate terraform resource for backend services, it's a little confusing. Can you elaborate a little where the creation of that part of the app happens?
Yeah the setup is admittedly a bit convoluted! The way it works is something like this:
- In the initial CI run there's no backend service, so the
K8S_BACKEND_SERVICE_NAME
environment variable here evaluates to""
- The environment variable is passed to Terraform as an input variable and is used to instantiate a load balancer in GCP
- After initializing the infra with Terraform, we apply the Kubernetes deployment
- applying the
Ingress
resource results in Terraform auto-creating a backend service for us (read more here https://github.com/kubernetes/ingress-gce)
- applying the
- Now in subsequent CI runs
gcloud compute backend-services list
points us to the backend service created by Terraform
So essentially it takes two CI runs to initialize this setup. This is due to the chicken-and-egg situation of needing to access the Kubernetes-created backend service to finish infra instantiation but not being able to apply Terraform without the infra.
Hope that makes any sense!
Thank you! That really helps, I appreciate it.
I'll leave it up to you to close this issue or leave it for others to read.