Home >Backend Development >Golang >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?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-23 22:19:30582browse

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.

The above is the detailed content of How to Identify and Delete Persistent Disks Associated with Deleted Kubernetes Engine Clusters?. 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