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
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.
Machine Types
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.
Persistent Disk
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 |
Name | No | No |
Labels | Yes | Yes |
Region | No | No |
Zone | No | No |
Machine configuration | ||
Machine family | No | Yes |
Series | No | Yes |
Machine type | No | Yes |
CPU platform | No | Yes |
GPUs | No | Yes |
Display device | No | Yes |
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 | ||
Operating system | No | No |
Version | No | No |
Boot disk type | No | No |
Size | No | Can only increase, via ‘Disks’ page |
Identity and API access | ||
Service account | No | Yes |
Firewall | ||
Allow HTTP traffic | Yes | Yes |
Allow HTTPS traffic | Yes | Yes |
Management, security, disks, networking, sole tenancy | ||
Management | ||
Description | No | No |
Deletion protection (Enable deletion protection) | Yes | Yes |
Reservations(Use an existing reservation when creating this VM instance) | No | No |
Automation | ||
Startup script | No | No |
Metadata | No | Yes |
Availability policy | ||
Preemptibility | No | No |
On host maintenance | Yes | Yes |
Automatic restart | Not available for pre-emptible instances | Not available for pre-emptible instances |
Security | ||
Shielded VM | ||
Turn on Secure Boot | No | Yes |
Turn on vTPM | No | Yes |
Turn on Integrity Monitoring | No | Yes |
SSH Keys | ||
Block project-wide SSH keys | Yes | Yes |
Public SSH keys | Yes | Yes |
Disks | ||
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 |
Additional disks | No | Yes |
Networking | ||
Network tags | Yes | Yes |
Hostname | No | No |
Network interfaces | Yes | Yes |
Sole tenancy | ||
Node affinity labels | No | No |
CPU overcommit | ||
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. |