0

I have NGINX setup on Google Cloud Compute Engine using a managed instance group setup [powered by managed instance templates].

I simulated a cpu load on one of the servers and that spawned a couple of additional servers, each running NGINX.

So what's the best practice for hosting a website using this?

  1. Do I just create an A-record in DNS and point it to the IP address of the original instance [of the group]? Looks like this would be problematic given that the IPs are ephemeral?!

  2. Do I reserve a static IP address [in VPC Network]? I tried to create a static IP address and attach it to the original instance in the group, but when I did that, the said instance went away leaving another spawned instance as the new primary instance?!

  3. Is there some load balancer hidden somewhere that I can point an A-record to?

Managed instance groups seem like a great idea, but would like to know the best way to set it up that will not break unexpectedly in DNS.

Grzenio
  • 35,875
  • 47
  • 158
  • 240
ObiHill
  • 11,448
  • 20
  • 86
  • 135

1 Answers1

3

You should setup a load balancer to distribute traffic across the instances in your group. To create a load balancer, you'll have to setup several components, instance groups being one of them. Check out this example. This uses unmanaged groups, but you can use managed instead. Once you've setup a load balancer, I would recommend creating a script in a language of your choice (python, JS, bash) that automates this process. I would even go further and write a script to tear down your load balancer.

As far as your domain is concerned, during the setup of your load balancer, you'll have to create static IPv4 and optional IPv6 addresses. You can then create A/AAAA records that point to these addresses. Finally, make sure you wait ~5-20 minutes after you've pointed your A/AAAA records to these ip's before you wonder why it's not working.

Vincent
  • 1,553
  • 1
  • 11
  • 21
  • Thanks for the link. I stumbled on a [YouTube video](https://www.youtube.com/watch?v=Gn7pGQYkKnA) that did a multi-regional setup of the google cloud load balancer using managed instance groups as the backend. It's a tad complicated, but seems to be one of the few ways to get a static IP in front of those virtual machines. – ObiHill Nov 19 '18 at 01:32
  • @ObinwanneHill yes it's a bit much at first, but if you can make a script to setup/tear it down, you won't have to think about it again. If you do make a script, you'll be more comfortable with the components that go into it and if you forget some part of the setup, you'll have code you can refer to so you can remember whats going on. – Vincent Nov 19 '18 at 01:44
  • And it's also doable via gcloud CLI, so I guess it's possible to wrap all those [gloud] commands inside of a node.js script?! All in good time. I just wanted to get my head around the basic workings/concepts of the load balancer in the gcloud environment. – ObiHill Nov 19 '18 at 02:15
  • @ObinwanneHill yea, definitely use gcloud in your scripts. – Vincent Nov 19 '18 at 02:16