Dear Concern,
Greetings of the day.
I have one customizable Compute Engine on GCP like a 2core vCPU, 5GB Ram, and 50GB storage and I want to decrease my machine resources. Now how do I decrease my Compute Engine resources without downtime, data, and file corruption?
Please, give me a sound solution to that issue so that I could decrease my resources from my end.
Warm Regards,
ASL Systems Ltd.
Solved! Go to Solution.
You can very easily change the memory and CPU configuration of a VM, but it does require brief downtime, as you need to shutdown the VM before making these changes, then start the VM, so a short period of unavailability. There is some guidance here: https://cloud.google.com/compute/docs/instances/changing-machine-type-of-stopped-instance
The disk is trickier, as a Persistent Disk cannot be reduced in size as Compute Engine has no access inside the operating system in order to reliably reduce the size (only grow) - for example if Compute Engine simply removed some blocks to reduce the size, how would it know if it was in use by the OS or not, so it would very much risk data loss and so it is not supported. Instead you would need to provision a new disk of the right size, copy the data over and then proceed to swap the disk over. The exact process to do this will depend on the operating system in use. There is a nice post here for Ubuntu for example: https://kobkrit.com/shrink-disk-in-google-cloud-platform-on-ubuntu-with-the-smallest-effort-possible...
Given you also say you want to minimise downtime, you don't mention a use of a Load Balancer, which would be ideal - as then you could simply clone the existing VM to a new one, modify the size to the new requirements and then configure the load balancer to shift traffic from the old to the new one. If this is a business critical application this might be something to explore for the future, although it would introduce some additional cost which may or may not be acceptable vs the short down time described above, something to balance.
You can very easily change the memory and CPU configuration of a VM, but it does require brief downtime, as you need to shutdown the VM before making these changes, then start the VM, so a short period of unavailability. There is some guidance here: https://cloud.google.com/compute/docs/instances/changing-machine-type-of-stopped-instance
The disk is trickier, as a Persistent Disk cannot be reduced in size as Compute Engine has no access inside the operating system in order to reliably reduce the size (only grow) - for example if Compute Engine simply removed some blocks to reduce the size, how would it know if it was in use by the OS or not, so it would very much risk data loss and so it is not supported. Instead you would need to provision a new disk of the right size, copy the data over and then proceed to swap the disk over. The exact process to do this will depend on the operating system in use. There is a nice post here for Ubuntu for example: https://kobkrit.com/shrink-disk-in-google-cloud-platform-on-ubuntu-with-the-smallest-effort-possible...
Given you also say you want to minimise downtime, you don't mention a use of a Load Balancer, which would be ideal - as then you could simply clone the existing VM to a new one, modify the size to the new requirements and then configure the load balancer to shift traffic from the old to the new one. If this is a business critical application this might be something to explore for the future, although it would introduce some additional cost which may or may not be acceptable vs the short down time described above, something to balance.
Hello, Alexmoore
Greetings of the day
Hope you are doing well, Many thanks for the guidance.
But if I reduce the resources to only CPU and memory, is there any possibility of application data loss?
Warm Regards
Asadul Islam.
If you cleanly shutdown the VM and make the changes, there should be minimal possibility of application data loss. The only thing to keep in mind is that by reducing the CPU and memory there is a chance you may over dial down the resources available for your application. I don't know what application you are running and I would hope that most applications would fail cleanly in the event they struggle with resources, however it is not entirely inconceivable that an application may behave erratically when it doesn't have enough resource. While that is an important problem from an application architecture standpoint, as a safeguard in this instance you could take a snapshot of the VM before restarting it with the reduced resources, then in the very unlikely event there is an issue you have a known good configuration to roll back to. Hope that helps.