[英]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:建议:
To answer your immediate question: you can programatically delete your disk resource(s) with the Method: disks.delete API.要回答您的直接问题:您可以使用方法以编程方式删除您的磁盘资源:disks.delete API。
To determine what other resources might have been allocated, look here: Listing all Resources in your Hierarchy .要确定可能已分配的其他资源,请查看此处: Listing all Resources in your Hierarchy 。
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注意事项
AND
is implicit and omittedAND
是隐式的且被省略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.