Home >Backend Development >Golang >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
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-"
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"
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!