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:
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:*"
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
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!