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.