Automating Persistent Disk Deletion on Cluster Deletion
In Kubernetes Engine (GKE), deleting a cluster does not automatically remove associated persistent disks. To address this issue and ensure efficient disk management, consider the following approach:
Identifying Associated Disks
Obtaining the names or IDs of associated persistent disks can be challenging since the cluster get API does not provide this information. However, you can leverage the Google Cloud SDK to identify the disks using filters and the desired format. Here are some examples:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-"
This command lists all disks used by a GKE cluster. You can customize the filter to meet your specific criteria, such as filtering by PVC disks:
gcloud compute disks list --format="table(name,users)" --filter="name~^gke-.*-pvc-.*"
Ensuring Disks Are Detached
Before deleting disks, it's important to ensure they are no longer in use by the cluster. Use the following kubectl command to list the cluster's PVs and their GCE PDs:
kubectl get pv -o custom-columns=K8sPV:.metadata.name,GCEDisk:spec.gcePersistentDisk.pdName
Deleting Associated Disks
Once you have identified the associated disks and ensured they are detached, you can proceed to delete them. The corresponding API method for this operation is disks.list.
By automating the identification and deletion of persistent disks during cluster deletion, you can streamline your workflow and ensure efficient disk management in GKE.
The above is the detailed content of How to Automate Persistent Disk Deletion During Kubernetes Engine Cluster Deletion?. For more information, please follow other related articles on the PHP Chinese website!