Home  >  Article  >  Backend Development  >  How to automatically delete persistent disks after deleting a Kubernetes cluster?

How to automatically delete persistent disks after deleting a Kubernetes cluster?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-23 18:52:30145browse

How to automatically delete persistent disks after deleting a Kubernetes cluster?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn