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

Susan Sarandon
Release: 2024-10-23 17:52:32
Original
956 people have browsed it

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-"
Copy after login
  • Disks used as PVCs:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"
Copy after login
  • Detached PVC disks (not in use by a cluster):
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.* AND -users:*"
Copy after login

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
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!