How to Automate Persistent Disk Deletion During Kubernetes Engine Cluster Deletion?

Mary-Kate Olsen
Release: 2024-10-23 17:20:02
Original
601 people have browsed it

How to Automate Persistent Disk Deletion During Kubernetes Engine Cluster Deletion?

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-"
Copy after login

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-.*"
Copy after login

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
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!