Question

I'm trying to accomplish something that was simple to do before in GCE with scratch disks. Basically I want to start an instance (now using a newly created root persistent disk), have the instance run some computation, then have the instance kill itself AND delete the root persistent disk.

This was easy before the V1 api because you could use a scratch disk that disappeared when the instance was killed, however, now with V1, deleting an instance with a root persistent disk requires two calls - one to delete the instance and one to delete the disk.

The issue is that if you want to do these 2 calls from the instance itself - which do you delete first? the instance or the disk? You cant do the disk because its in use by the instance, and if you kill the instance first then how will the instance be used to kill the disk?

Was it helpful?

Solution

I don't think you can achieve exactly what you described. The instance needs the disk while it is running. After it shuts down you can delete the disk.

Google compute engine exposes REST API. You can issue the calls to delete disk and remove instance from some other machine (i.e. your work machine). If you want to, you can even use AppEngine to help you with this. An instance could put a task onto the task queue before it shuts down, and the AppEngine task, which would run a bit later could properly clean up the GCE instance. You could also use AppEngine to run a small admin application which could help you with managing your GCE instances.

OTHER TIPS

You can use setAutoDiskDelete option. Setting this option will delete the disk when an instance is deleted. This way you can delete the instance from inside VM and that will trigger disk deletion.

Ref: https://cloud.google.com/compute/docs/reference/beta/instances/setDiskAutoDelete

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top