epiphone / gke-terraform-example

A sample web app deployment on Google Kubernetes Engine
44 stars 29 forks source link

Backend service creation ambigious #3

Open dionjwa opened 4 years ago

dionjwa commented 4 years ago

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?

epiphone commented 4 years ago

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
  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!

dionjwa commented 4 years ago

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.