Home  >  Article  >  Backend Development  >  How to Identify and Delete Persistent Disks Associated with a GKE Cluster?

How to Identify and Delete Persistent Disks Associated with a GKE Cluster?

Susan Sarandon
Susan SarandonOriginal
2024-10-23 17:52:32961browse

How to Identify and Delete Persistent Disks Associated with a GKE Cluster?

Deleting Associated Persistent Disks Upon Cluster Deletion

In Kubernetes Engine, it's expected that persistent disks attached to a cluster will remain after cluster deletion. However, users may desire to delete these disks simultaneously for various reasons. Determining the disk names or IDs to delete can be challenging, as the Cluster get API lacks disk-related information.

Solution

The recommended approach to identify disks associated with a GKE cluster is through the Cloud SDK. By utilizing filters and appropriate formatting, users can retrieve a list of disks:

  • All GKE disks:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-"
  • Disks used as PVCs:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"
  • Detached PVC disks (not in use by a cluster):
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.* AND -users:*"

To verify that a detached disk is not in use, users can employ the following kubectl command:

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

The corresponding API method for obtaining a list of disks is disks.list.

Note: The filters and formatting options presented may vary depending on the specific requirements of the user's environment. It's advisable to adjust the commands accordingly to suit their use case.

The above is the detailed content of How to Identify and Delete Persistent Disks Associated with a GKE 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