gke-terraform-example icon indicating copy to clipboard operation
gke-terraform-example copied to clipboard

Backend service creation ambigious

Open dionjwa opened this issue 5 years ago • 2 comments

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?

dionjwa avatar Nov 01 '19 22:11 dionjwa

Yeah the setup is admittedly a bit convoluted! The way it works is something like this:

  1. In the initial CI run there's no backend service, so the K8S_BACKEND_SERVICE_NAME environment variable here evaluates to ""
  2. The environment variable is passed to Terraform as an input variable and is used to instantiate a load balancer in GCP
  3. 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)
  4. 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!

epiphone avatar Nov 05 '19 05:11 epiphone

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.

dionjwa avatar Nov 06 '19 17:11 dionjwa