简体   繁体   English

使用 gcloud container clusters create 创建的 GKE 集群后如何清理?

[英]How to clean up after a GKE cluster created with gcloud container clusters create?

I'm creating Kubernetes clusters programmatically for end-to-end tests in GitLab CI/CD.我正在以编程方式创建 Kubernetes 集群,以在 GitLab CI/CD 中进行端到端测试。 I'm using gcloud container clusters create .我正在使用gcloud container clusters create I'm doing this for half a year and created and deleted a few hundred clusters.我这样做了半年,创建和删除了数百个集群。 The cost went up and down.成本上升和下降。 Now, I got an unusually high bill from Google and I checked the cost breakdown.现在,我从谷歌收到了一笔异常高的账单,我查看了成本明细。 I noticed that the cost is >95% for "Storage PD Capacity".我注意到“存储 PD 容量”的成本 >95%。 I found out that gcloud container clusters delete never deleted the Google Compute Disks created for Persistent Volume Claims in the Kubernetes cluster.我发现gcloud container clusters delete从未删除为 Kubernetes 集群中的 Persistent Volume Claims 创建的 Google Compute Disks。

How can I delete those programmatically?我怎样才能以编程方式删除那些? What else could be left running after deleting the Kubernetes cluster and the disks?删除 Kubernetes 集群和磁盘后还能运行什么?

Suggestions:建议:

  1. To answer your immediate question: you can programatically delete your disk resource(s) with the Method: disks.delete API.要回答您的直接问题:您可以使用方法以编程方式删除您的磁盘资源:disks.delete API。

  2. To determine what other resources might have been allocated, look here: Listing all Resources in your Hierarchy .要确定可能已分配的其他资源,请查看此处: Listing all Resources in your Hierarchy

  3. Finally, this link might also help: GKE: Understanding cluster resource usage最后,此链接也可能有帮助: GKE: Understanding cluster resource usage

Because this part of the answer is lengthy:因为这部分答案很长:

gcloud compute disks create disk-a \
--size=10gb \
--zone=us-west1-a \
--labels=something=monday \
--project=${PROJECT}

gcloud compute disks create disk-b \
--size=10gb \
--zone=us-west1-b \
--labels=something=else \
--project=${PROJECT}

Then:然后:

ID=$(gcloud compute disks list \
--filter="name~disk zone~us-west1 labels.something=else" \
--format="value(id)" \
--project=${PROJECT}) && echo ${ID}

NB注意事项

  • the filter AND is implicit and omitted筛选器AND是隐式的且被省略
  • you may remove terms as needed您可以根据需要删除条款
  • you should make the filter as specific as possible您应该使过滤器尽可能具体


And -- when you're certain as deletion is irrecoverable:并且 - 当您确定删除不可恢复时:

gcloud compute disks delete ${ID} --project=${PROJECT} --region=${REGION}

If there are multiple matches, you can iterate:如果有多个匹配项,则可以迭代:

IDS=$(gcloud compute disks list ...)
for ID in ${IDS}
do
  gcloud compute disks delete ${ID}
done

If you prefer -- the awesome jq , you'll have a general-purpose way (not gcloud -specific):如果你喜欢——很棒的jq ,你将有一个通用的方法(不是gcloud特定的):

gcloud compute disks list \
--project=${PROJECT} \
--format=json \
| jq --raw-output '.[] | select(.name | contains("disk")) | select(.zone | contains("us-west1")) | select(.labels.something=="else")'
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ERROR: (gcloud.beta.container.clusters.create) ResponseError: code=400, message=v1 API 无法用于访问 GKE 区域集群 - ERROR: (gcloud.beta.container.clusters.create) ResponseError: code=400, message=v1 API cannot be used to access GKE regional clusters 将 gcloud container clusters create --scope 转换为 Terraform 配置 - translating gcloud container clusters create --scope into a Terraform config 如何在不使用 gcloud CLI 的情况下向 GKE 集群进行身份验证 - How to authenticate to a GKE cluster without using the gcloud CLI 为什么 gcloud container clusters get-credentials 会弄乱我的 Linux 用户权限? - Why gcloud container clusters get-credentials messes up my Linux user permissions? GKE 集群节点以 CrashLoopBackOff 结束 - GKE cluster node ends up with CrashLoopBackOff 容器/GKE 集群:强制启用 Web UI - Container/GKE cluster: Force enable Web UI 如何在 gcloud 和 minikube 之间切换 kubectl 集群 - How to switch kubectl clusters between gcloud and minikube 不断获取权限错误 gcloud.container.clusters.get-credentials - Keep getting permissions error gcloud.container.clusters.get-credentials 用于 GKE 集群的维护 window - Maintenance window for GKE clusters 无法在使用“带有 Docker 的 Ubuntu”映像创建的 GKE 集群上部署 pod - Unable to deploy pods on GKE cluster created using 'Ubuntu with Docker' image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM