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.
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