Deleting all the associate persistent disks when deleting cluster

1/9/2020

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
go
google-cloud-platform
google-kubernetes-engine
google-persistent-disk

4 Answers

1/31/2020

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
Source: StackOverflow

1/10/2020

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
Source: StackOverflow

1/15/2020
-- jkamwa
Source: StackOverflow

1/16/2020

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
Source: StackOverflow