3

According to the documentation when deleting a cluster the persistent disk will still exist(https://cloud.google.com/kubernetes-engine/docs/how-to/deleting-a-cluster). I wanna delete all the associate persistent disks when deleting cluster but I don't know the name/id of persistent disk. Cluster get API doesn't have any information about the disks and nodes.

resp, err := containerService.Projects.Zones.Clusters.Get(project, zone, cluster).Context(ctx).Do()

SamiraM
  • 61
  • 7
  • Were you using stateful sets? – dany L Jan 09 '20 at 00:26
  • can you elaborate what kind of disk ? like are you referring to node disk or the PV storage? by default the node disk have the same node name, if that what you are looking for let me know – Alioua Jan 09 '20 at 02:29
  • would you as well provide the documentation that mention when deleting a cluster the persistent disk will still exist? – Alioua Jan 09 '20 at 04:45
  • @Alioua, Yes I am talking about persistent disk which is the same name as the node. but as the node is created dynamically in cluster creation how can get the node name? I used the get api but didn't have this info. – SamiraM Jan 09 '20 at 21:48
  • @Alioua here is the document I was referring for when deleting a cluster PD will to get delete. https://cloud.google.com/kubernetes-engine/docs/how-to/deleting-a-cluster – SamiraM Jan 09 '20 at 21:50
  • @danyL , yes I am using statefulsets – SamiraM Jan 15 '20 at 21:42

4 Answers4

3

Cloud SDK can be used to identify the disks if the proper filter and format are parse

i.e.

To list all the disks being used by a GKE (you can change the filter at your convenience)

gcloud compute disks list --format="table(name,users)" --filter="name~^gke-"

To list only disks used as PVC

gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"

This last command will list detached PVC disks

gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.* AND -users:*"

To ensure a detached disk is not in use by a cluster, here's a kubectl command to list a cluster's PVs and their GCE PD:

kubectl get pv -o custom-columns=K8sPV:.metadata.name,GCEDisk:spec.gcePersistentDisk.pdName

The corresponding API method is disks.list

Carlos
  • 966
  • 7
  • 15
  • How do you do this filtering with GCP API? when I use the same filter you mention here. Gives the invalid filter error in api. https://cloud.google.com/compute/docs/reference/rest/v1/disks/list – SamiraM Feb 05 '20 at 23:49
0

To get the node name run , then the disk name is the same as the node name. You can delete the disk after the cluster but you need to run kubectl get nodes before the deletion. Also to get the disk id, you can use gcloud command: gcloud compute disks describe --zone < ZONE> | grep "id" Follow this link for Google best practices on how to delete cluster disks:link

jkamwa
  • 21
  • 1
0

In order to achieve what you are looking for the following google docs will be helpful to get the node name through Go API using two methods1<nodeget> 2 <instagroupget>

jkamwa
  • 21
  • 1
  • With these can get the baseinstanceName and delete based on that ... It doesn't give the nodes name/id. Also, what if the cluster is already deleted. – SamiraM Jan 16 '20 at 03:16
  • @Samira both method should be used before delete your cluster in order to get the disk name the first one is to get the instance group manager for the node pool and the second method is used to get the instance name from the instance group manager (keep in mind the disk name is the same as the node name) you can use both method in one Golang script to get the disk name in first the delete the cluster and then delete the disk after all these in one script. Let me know the output. – Alioua Jan 16 '20 at 04:42
  • @Alioua As I mentioned above the Get instanceGroupManager doesn't have name/id of the nodes. the only relevant field is the baseInstanceName. here is the page I am referring to https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroupManagers/get – SamiraM Jan 16 '20 at 19:29
  • Oh ok then this [method](https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroupManagers/listManagedInstances) will give you the instance name field – Alioua Jan 17 '20 at 04:11
0

For stateteful sets, a disk in the following format will be created

gke-standard-cluster-3-pvc-8586b7f8-37fd-11ea-beff-42010a80012a

Where standard-cluster-3 will be the name of your cluster and pvc-8586b7f8-37fd-11ea-beff-42010a80012a will be the name of your volume

That said you can use this method to catch the name of a persistent disk created by a stateful set.

jkamwa
  • 21
  • 1