简体   繁体   English

删除 Google Cloud 项目中的所有资源

[英]Delete all resources in a Google Cloud Project

One of my project contains many resources, which are created from different sources, means some from Deployment Manager API and some from Console by users.I need to delete all resources without deleting(shutting down) the project .In this case, is there any API endpoints which can delete all resources in this project including both created from Deployment Manager and Console?我的项目之一包含许多资源,这些资源是从不同来源创建的,意味着一些来自 Deployment Manager API,一些来自用户的控制台。我需要删除所有资源而不删除(关闭)项目。在这种情况下,是否有任何API 可以删除此项目中所有资源的端点,包括从 Deployment Manager 和控制台创建的资源?

I wrote Safe Scrub to do exactly that: Clean up resources from across Google Cloud, including GCE, AppEngine, GKE, CloudSQL, and more.我编写了Safe Scrub 就是为了做到这一点:清理整个 Google Cloud 中的资源,包括 GCE、AppEngine、GKE、CloudSQL 等。

It has a focus on safety.它注重安全。 For example, it does not actually delete any resources, but rather generates a script (a list of delete commands) that you can review and run.例如,它实际上并没有删除任何资源,而是生成一个您可以查看和运行的脚本(删除命令列表)。

Feedback is appreciated.反馈表示赞赏。

I don't think something like that exists, and it would be pretty dangerous if someone could just click on a button and shutdown/delete everything in a project, if you do a mistake with this you are in a position I don't want to think about.我不认为这样的事情存在,如果有人可以点击一个按钮并关闭/删除项目中的所有内容,那将是非常危险的,如果您在此方面犯了错误,您将处于我不想要的位置想一下。

A way to do what you want is something like a bash script that would use gcloud commands to delete what you need to delete.一种做你想做的事情就像一个 bash 脚本,它会使用 gcloud 命令来删除你需要删除的内容。

Someone already tried but didn't go very far: https://github.com/enxebre/bazooka有人已经尝试过但没有走多远: https : //github.com/enxebre/bazooka

Like night-gold said in the First Answer, right now there is no API endpoint to delete all resources inside a project.I discussed with a Google Cloud Engineer, and reply from him was:就像夜金在First Answer中所说的,现在没有API端点来删除项目内的所有资源。 我和谷歌云工程师讨论过,他的回复是:

"You will be able to delete the Deployment Manager resource by deleting the deployment itself. The resources created by a user through the console must be addressed individually. You can automate deleting the resources made by a user. Some suggested tools for accomplishing this would be to use Chef, Puppet, Ansible, Terraform, &/or shell scripts." “您将能够通过删除部署本身来删除部署管理器资源。用户通过控制台创建的资源必须单独处理。您可以自动删除用户创建的资源。一些建议的工具用于完成此操作使用 Chef、Puppet、Ansible、Terraform 和/或 shell 脚本。”

您可以使用部署 API 的列表方法来收集所有部署,然后使用删除方法删除部署和所有资源。

With the appropriate IAM config, here's how to delete all Endpoints for a given project :使用适当的 IAM 配置,以下是删除给定项目的所有端点的方法:

#!/bin/bash
# 
# A script to delete all endpoints for a given project
# Usage: ./delete-endpoints.sh project-id

PROJECT=$1

ENDPOINTS=($(gcloud --project=${PROJECT} endpoints services list --format="value(serviceName)"))
for i in "${ENDPOINTS[@]}"
do
        gcloud -q endpoints services delete $i --async
done

Similar scripts can delete all kinds of resources using gcloud类似的脚本可以使用gcloud删除各种资源

In my project, we are using cats-love-money which is a simple script to remove pricey GCP resources (composers, GKEs, Dataprocs).在我的项目中,我们使用了cats-love-money ,这是一个简单的脚本来删除昂贵的GCP 资源(composer、GKE、Dataprocs)。 By default, we remove everything older than 24h and without please-do-not-kill-me label.默认情况下,我们会删除早于 24 小时且没有please-do-not-kill-me标签的所有内容。

It can be deployed on schedule using cloud functions and scheduler.它可以使用云功能和调度程序按计划部署。 It saves us a lot of cash.它为我们节省了大量现金。

Actually you can do this.其实你可以这样做。 Simply go to "IAM & Admin" -> "Manage Resources".只需转到“IAM 和管理”->“管理资源”。 This will take you to a management screen for your projects and you can delete them, see the billing, etc.这将带您进入项目的管理屏幕,您可以删除它们、查看账单等。

I wrote another project, Cloud Blaster to do exactly that: Clean up resources from across Google Cloud, including GCE, AppEngine, GKE, CloudSQL, and more.我写了另一个项目Cloud Blaster来做这件事:清理整个 Google Cloud 中的资源,包括 GCE、AppEngine、GKE、CloudSQL 等。

Unlike my shell-script SafeScrub, mentioned in an answer above, this is in Kotlin and so is more flexible and robust to change.与上面答案中提到的我的 shell 脚本 SafeScrub 不同,它位于 Kotlin 中,因此更灵活,更易于更改。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM