How to Delete All Persistent Disks Associated with a Deleted Cluster
When a Kubernetes cluster is deleted, persistent disks (PDs) associated with it may persist. To automatically delete these PDs, identify their names or IDs.
Solution:
The Cloud SDK can be utilized with specific filters and formatting to list the disks associated with a GKE cluster.
Command to List All Disks Used by a GKE Cluster:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-"
Command to List Only Disks Used as PVC:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"
Command to List Detached PVC Disks:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.* AND -users:*"
Kubernetes Command to List Cluster's PVs and PD Names:
kubectl get pv -o custom-columns=K8sPV:.metadata.name,GCEDisk:spec.gcePersistentDisk.pdName
API Method for Listing Disks:
disks.list
The above is the detailed content of How to automatically delete persistent disks after deleting a Kubernetes cluster?. For more information, please follow other related articles on the PHP Chinese website!