"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Identify and Delete Persistent Disks Associated with Deleted Kubernetes Engine Clusters?

How to Identify and Delete Persistent Disks Associated with Deleted Kubernetes Engine Clusters?

Published on 2024-12-22
Browse:604

How to Identify and Delete Persistent Disks Associated with Deleted Kubernetes Engine Clusters?

Cleaning Up Persistent Disks Associated with Deleted Clusters

When deleting a Kubernetes Engine cluster, the persistent disks associated with the cluster by default remain intact. To address this, you can leverage the Cloud SDK to identify and delete these disks.

Identifying Persistent Disks

Cloud SDK provides a versatile command-line interface to interact with Google Cloud resources. Using the gcloud compute disks list command with appropriate filters and formatting options, you can retrieve a list of disks based on their names or associated users.

Recommended Filters

  • To list all disks used by a GKE cluster:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-"
  • To list only disks used as Persistent Volume Claims (PVCs):
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"
  • To list detached PVC disks:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.* AND -users:*"

Verifying Disk Status with Kubernetes

To ensure that a detached disk is not in use by a cluster, you can use the kubectl command:

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

This command will list Persistent Volumes (PVs) and their corresponding Google Compute Engine Persistent Disk (PD) names.

Cleaning Up Disks

Once you have identified the disks you want to delete, you can use the gcloud compute disks delete command to remove them.

API Reference

The corresponding API method for listing disks is disks.list.

Release Statement This article is reprinted at: 1729674873 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3