Few months ago I started the
streetcred project on Google Cloud Platform, scheduling scraping tasks on Google Compute Engine. Here are some things I learnt about editing Google Compute Engine instance settings after instance creation, so that you don’t have to go through the same trouble if you’re ever starting a similar project of your own. Most of this information is probably in documentation somewhere but being lazy I missed them and learnt them the long way.
Pre-emptible instances are compute instances that may be reclaimed by Google any time resources are required, or at the end of 24 hours. In exchange for that drawback, pre-emptible instances are much cheaper to run. They’re great for non-critical, fault tolerant jobs on a budget.
1. You cannot change the instance’s pre-emptiblity once the instance is set up
The only way to keep the same instance name and configuration and toggle between a regular and pre-emptible instance, is to delete the old instance and create a new one. The option is only available during initial set up.
2. Pre-emptible instances do not restart on their own
From experience the instances generally shutdown at the 24 hour mark (rather than earlier). To use them as (almost) always on instances, you’ll need a separate persistent instance running to check if your pre-emptible instance is down, and send a call to restart it. Not to worry about costs of the additional instance though, as you can use your free instance quota to run this task. Due to these reasons and more, I created
gcloud-monitor to make the most out of pre-emptible instances. Read more about it here.
Here’s to select from pre-defined or custom machine types, from things like the number of vCPUs to the amount of RAM.
3. You’ll need to stop your instance to change its machine type
If your task cannot be stopped safely for a period of time once it is started, then you might consider it not possible to change your machine type, and need to select more carefully on creation. More on changing machine types here.
4. Don’t always trust performance recommendations
Sometimes instances crash if the recommendations are not followed and resource consumption explodes. Sometimes it doesn’t. If cost is a main concern you’ll need to dabble a little with the machine type configurations to get the hang of what is sufficient. Recommendations are not (always) critical warnings.
This refers to the persistent storage capacity of your instance.
5. Persistent disk capacity can be increased but not decreased
Once your instance is created, you won’t be able to reduce the size of the persistent disk. If cost is a concern in the running of your instance, then you may want to try with a small size and increasing it later on, rather than the other way round. More on resizing persistent disks here.
Editing Google Compute Engine Settings Post-creation
|Field||Can edit without stopping instance||Can edit upon stopping instance|
|Confidential VM service (Enable the Confidential Computing service on this VM instance.)||No||No|
|Container (Deploy a container image to this VM instance.)||No||No|
|Boot disk type||No||No|
|Size||No||Can only increase, via ‘Disks’ page|
|Identity and API access|
|Allow HTTP traffic||Yes||Yes|
|Allow HTTPS traffic||Yes||Yes|
|Management, security, disks, networking, sole tenancy|
|Deletion protection (Enable deletion protection)||Yes||Yes|
|Reservations(Use an existing reservation when creating this VM instance)||No||No|
|On host maintenance||Yes||Yes|
|Automatic restart||Not available for pre-emptible instances||Not available for pre-emptible instances|
|Turn on Secure Boot||No||Yes|
|Turn on vTPM||No||Yes|
|Turn on Integrity Monitoring||No||Yes|
|Block project-wide SSH keys||Yes||Yes|
|Public SSH keys||Yes||Yes|
|Boot disk Deletion rule Delete boot disk when instance is deleted||Yes||Yes|
|Encryption Data is encrypted automatically. Select an encryption key management solution.||No||No|
|Device name Used to reference the device for mounting or resizing.||No||Yes|
|Node affinity labels||No||No|
|Enable CPU overcommit||No||Only allowed for a machine type of 4 or more vCPUs.
Only allowed for VMs scheduled onto sole-tenant nodes enabled for CPU overcommit.