執行這項工具,判斷Google Cloud 專案、資料夾或機構內是否有 Container Registry 用量。
事前準備
-
Install the Google Cloud CLI.
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
gcloud init
必要的角色
如要取得在 Google Cloud 專案、資料夾或組織中查看 Container Registry 用量的權限,請要求管理員授予您下列 IAM 角色:
-
Cloud Asset 檢視者 (
roles/cloudasset.viewer) 專案、資料夾或機構的 Google Cloud -
Storage 物件檢視者 (
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 bucket。Container Registry 關閉後,這個專案仍會繼續運作,不需要採取進一步行動。您可以刪除 Container Registry Cloud Storage bucket 來降低費用。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 bucket。Container Registry 關閉後,這個專案仍會繼續運作,不需要採取進一步行動。您可以刪除 Container Registry Cloud Storage bucket 來降低費用。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 bucket。Container Registry 關閉後,這個專案仍會繼續運作,不需要採取進一步行動。您可以刪除 Container Registry Cloud Storage bucket 來降低費用。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 或參閱參考文件。