Delete GCE instance AND its root persistent disk from within the instance

依然范特西╮ 提交于 2019-12-12 01:12:36

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/20846556/delete-gce-instance-and-its-root-persistent-disk-from-within-the-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!