執行這項工具,判斷Google Cloud 專案、資料夾或機構是否有使用 Container Registry。
事前準備
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
必要的角色
如要取得在 Google Cloud 專案、資料夾或機構中查看 Container Registry 用量的權限,請要求管理員授予您下列 IAM 角色:
-
Google Cloud 專案、資料夾或機構中的 Cloud Asset 檢視器 (
roles/cloudasset.viewer
) -
Google Cloud 專案、資料夾或機構的 Storage 物件檢視者 (
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 用途不明。這種狀態是因為舊版 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
或參閱參考說明文件。