运行此工具,确定您的Google Cloud 项目、文件夹或组织中是否存在 Container Registry 使用情况。
准备工作
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
所需的角色
如需获得在 Google Cloud 项目、文件夹或组织中查找 Container Registry 使用情况所需的权限,请让管理员向您授予以下 IAM 角色:
-
Google Cloud 项目、文件夹或组织的 Cloud Asset Viewer (
roles/cloudasset.viewer
) -
Storage Object Viewer (
roles/storage.objectViewer
) 针对 Google Cloud 项目、文件夹或组织
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
查找 Container Registry 用量
您可以运行该工具,并将其范围限定为单个 Google Cloud 项目、文件夹或组织。
项目
运行以下命令,查找Google Cloud 项目中所有 Container Registry 的使用情况。
gcloud container images list-gcr-usage \
--project=PROJECT
其中,PROJECT 是您的 Google Cloud 项目 ID。 如需了解如何查找项目 ID,请参阅标识项目。
该工具会返回指定项目的宿主位置列表及其使用状态。使用情况状态的定义如下:
ACTIVE
:过去 30 天内使用了 Container Registry。宿主位置和项目不会重定向。INACTIVE
:过去 30 天内未发生任何 Container Registry 用量。宿主位置和项目不会重定向。REDIRECTED
:项目已重定向到 Artifact Registry,但仍有 Container Registry Cloud Storage 存储分区。在 Container Registry 关停后,此项目将继续运行,无需采取进一步行动。您可以删除 Container Registry Cloud Storage 存储分区,以降低费用。REDIRECTION_INCOMPLETE
:请求已重定向到 Artifact Registry,但数据仍在从 Container Registry 复制。LEGACY
:Container Registry 用量未知。此状态是由旧版 Container Registry 项目导致的,这些项目将容器映像元数据文件存储在 Cloud Storage 存储分区中。如需详细了解旧版 Container Registry 项目,请参阅容器映像元数据存储变更。
如果该工具遇到错误,例如缺少查看 Cloud Storage 存储桶或 Container Registry 项目的权限,您将看到类似于以下内容的错误消息:
repository: us.gcr.io/my-project
usage: |-
response: {'status': 401}
Operation on project 'no-gcr-permission' failed. Caller does not have permission 'storage.objects.list'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control: None
文件夹
运行以下命令,查找Google Cloud 文件夹中对 Container Registry 的任何使用情况。
gcloud container images list-gcr-usage \
--folder=FOLDER
其中,FOLDER 是您的 Google Cloud 文件夹 ID。如需了解如何列出组织中的文件夹,请参阅列出文件夹。
该工具会返回以下使用情况状态列表:
ACTIVE
:过去 30 天内使用了 Container Registry。宿主位置和项目不会重定向。INACTIVE
:过去 30 天内未发生任何 Container Registry 用量。宿主位置和项目不会重定向。REDIRECTED
:项目已重定向到 Artifact Registry,但仍有 Container Registry Cloud Storage 存储分区。在 Container Registry 关停后,此项目将继续运行,无需采取进一步行动。您可以删除 Container Registry Cloud Storage 存储分区,以降低费用。REDIRECTION_INCOMPLETE
:请求已重定向到 Artifact Registry,但数据仍在从 Container Registry 复制。LEGACY
:Container Registry 用量未知。此状态是由旧版 Container Registry 项目导致的,这些项目将容器映像元数据文件存储在 Cloud Storage 存储分区中。如需详细了解旧版 Container Registry 项目,请参阅容器映像元数据存储变更。
如果该工具遇到错误,例如缺少查看 Cloud Storage 存储桶或 Container Registry 项目的权限,您将看到类似于以下内容的错误消息:
repository: us.gcr.io/my-project
usage: |-
response: {'status': 401}
Operation on project 'no-gcr-permission' failed. Caller does not have permission 'storage.objects.list'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control: None
组织
运行以下命令,查找您Google Cloud 组织中的任何 Container Registry 用量。
gcloud container images list-gcr-usage \
--organization=ORGANIZATION
其中 ORGANIZATION 是您的 Google Cloud 组织 ID。如需了解如何查找组织 ID,请参阅获取组织资源 ID。
该工具会返回以下使用情况状态列表:
ACTIVE
:过去 30 天内使用了 Container Registry。宿主位置和项目不会重定向。INACTIVE
:过去 30 天内未发生任何 Container Registry 用量。宿主位置和项目不会重定向。REDIRECTED
:项目已重定向到 Artifact Registry,但仍有 Container Registry Cloud Storage 存储分区。在 Container Registry 关停后,此项目将继续运行,无需采取进一步行动。您可以删除 Container Registry Cloud Storage 存储分区,以降低费用。REDIRECTION_INCOMPLETE
:请求已重定向到 Artifact Registry,但数据仍在从 Container Registry 复制。LEGACY
:Container Registry 用量未知。此状态是由旧版 Container Registry 项目导致的,这些项目将容器映像元数据文件存储在 Cloud Storage 存储分区中。如需详细了解旧版 Container Registry 项目,请参阅容器映像元数据存储变更。
如果该工具遇到错误,例如缺少查看 Cloud Storage 存储桶或 Container Registry 项目的权限,您将看到类似于以下内容的错误消息:
repository: us.gcr.io/my-project
usage: |-
response: {'status': 401}
Operation on project 'no-gcr-permission' failed. Caller does not have permission 'storage.objects.list'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control: None
过滤结果
如需控制列出哪些资源项,请传递 --filter=EXPRESSION
标志。如果表达式对给定项的计算结果为 true,则会列出该项。
如需列出组织中的所有有效 Container Registry 用量,您可以按有效用量进行过滤:
gcloud container images list-gcr-usage \
--organization=ORGANIZATION \
--filter="usage=ACTIVE"
如需查找尚未重定向的所有项目,您可以按 usage!=REDIRECTED
进行过滤:
gcloud container images list-gcr-usage \
--organization=ORGANIZATION \
--filter="usage!=REDIRECTED"
如需详细了解过滤条件表达式,请运行 gcloud topic filters
或阅读参考文档。