GCP cost optimization comes in three main ways: adjusting Compute Engine machines in accordance with application requirements, switching to HDD storage and using Standard network tier instead of Premium.
Machine types on GCP are highly customizable, thus it is advised to user
n1-highcpu-x machines for CPU-intensive and
n1-highmem-x for RAM-intensive loads.
To change a virtual machine's type, simply stop it and edit the machine type as stated in the official documentation.
HDD-based provisioned storage disks are 425% cheaper than SSD-based ones.
To migrate a machine from SSD to HDD, do the following steps:
Stop the instance
Create a snapshot of the boot disk attached to the machine
Unassign the external IP address from the instance
Create a new instance and specify the previously created snapshot as the source, assign the right external IP address and attach extra data disks if any
Remove the old instance
Enjoy the migrated machine with storage costs greatly reduced!
Note: You may want to keep the disk snapshot for some time to be able to recreate the VM in case of any issues with the previously created one
To set the default tier for a project, follow this document.