运行此工具以确定您的 Google Cloud 项目、文件夹或组织中是否使用了 Container Registry。
准备工作
所需的角色
如需获取在 Google Cloud 项目、文件夹或组织中查找 Container Registry 使用情况所需的权限,请让管理员授予您以下 IAM 角色:
-
对 Google Cloud 项目、文件夹或组织拥有 Cloud Asset Viewer (
roles/cloudasset.viewer
) 权限 -
拥有 Google Cloud 项目、文件夹或组织的 Storage Object Viewer (
roles/storage.objectViewer
) 权限
如需详细了解如何授予角色,请参阅管理访问权限。
查找 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 使用情况未知。此状态是由在 Cloud Storage 存储分区中存储容器映像元数据文件的旧版 Container Registry 项目引起的。如需详细了解旧版 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 使用情况未知。此状态是由在 Cloud Storage 存储分区中存储容器映像元数据文件的旧版 Container Registry 项目引起的。如需详细了解旧版 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 使用情况未知。此状态是由在 Cloud Storage 存储分区中存储容器映像元数据文件的旧版 Container Registry 项目引起的。如需详细了解旧版 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
或阅读参考文档。