0

I signed up for Google Cloud the other day using their free trial promotion. I love it so far. I've got a couple of questions that are probably generic to cloud computing, which I'm new to. I have my test virtual machine up without any issues, using Ubuntu Linux.

My question with cloud concepts are - first: - How to scale instance. Can you scale from micro to small (also vice versa)?

  • If scaling isn't done that way, and it's about using instance groups, how do load balancing and instance groups work?

  • This is the concept I'm most confused with...how would I push an code update if I had 3 instances for the load balancer?

Thanks for your help!

TJ Nevis
  • 41
  • 2

1 Answers1

1

First question: How do you vertically scale an instance? Answer: you must re-create the instance and destroy the old one. You can't just make an existing instance smaller or larger. Luckily, you can script the whole setup. GCE allows you to add a flag called --metadata-from-file. If you are using systemd, I recommend something to the effect of --metadata-from-file user-data=cloud-config.yaml. Since you are using Ubuntu, and Ubuntu's support for systemd is sketchy at best, you probably just want to do something like: --metadata-from-file startup-script=my-startup-script.sh Scripting your deployment will allow you to scale, re-create and document your deployment and is a best practice in cloud computing.

Second question: How do instance groups and load balancing groups work? Answer: Instance groups in GCE are almost always of the "managed" variety. This allows you to create a template that defines how you want your instances to work. Then you can horizontally scale them (i.e. add more or take some away) behind a load balancer. You can even leverage preemptible instances to save you some cash.

Third question: How do I push an update? This depends on how you deploy. But in general I would say:

  • If you use Docker, push a new image to GCR and have your instances pull it.
  • If you use CM (like Salt or Ansible) just use those tools normally. They work fine on GCE
  • If you use startup scripts do something like gcloud compute instances myinstance add-metadata metadata-from-file startup-script=newScript.sh (and restart after)
  • If everything is contained in a managed instance template, update your template.
bbuckley123
  • 1,519
  • 10
  • 16
  • Thanks. This has been really helpful. I am, however, running into a little issue. It's probably because I don't quite know what I'm doing. So, I figured out load balancing, how to set a startup script or set a Google Storage resource (startup-script-url), and found some startup scripts. I can't seem to figure out how to git pull a private repo - I think that's what my issue is. And the git repo that comes with a project (https://source.developers.google.com/p/projectID) is private, I think. – TJ Nevis Oct 16 '15 at 02:39
  • This is the script I'm trying to get working: set -v # Talk to the metadata server to get the project id PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google") export HOME=/nodejs git config --global credential.helper gcloud.sh if [ -d "/nodejs" ]; then cd /nodejs git pull else git clone https://source.developers.google.com/p/$PROJECTID /nodejs fi – TJ Nevis Oct 16 '15 at 02:40
  • When I run the script manually, after setting chmod +x startup.sh, it asks for a username and password and directs me to https://code.google.com/hosting/settings for data to put in my .netrc file. I'm not sure that's right. And I'm not sure what the answer is. I've been Googling forever and either I'm not writing the correct keywords or I'm just missing the solution. I'm not sure where to go from here. Thanks for your insight! – TJ Nevis Oct 16 '15 at 02:42
  • The first bit about scaling an instance has been out of date for a while. You can stop an instance, edit its size and restart it. [Docs](https://cloud.google.com/compute/docs/instances/changing-machine-type-of-stopped-instance) – ZachB May 31 '16 at 22:20