將 Artifact Registry 做為工作負載映像檔的私人登錄檔

本頁說明如何設定 Google Distributed Cloud (僅限軟體),讓 VMware 管理員叢集使用 Google 的 Artifact Registry 做為私人 Docker 登錄檔,儲存工作負載映像檔。設定私人登錄檔來儲存工作負載映像檔時,建立或升級叢集時,Google Distributed Cloud 系統映像檔也會儲存在私人登錄檔中。

雖然 Artifact Registry 支援多種驗證方法,但如要將 Artifact Registry 做為私人登錄檔使用,就必須使用服務帳戶金鑰進行驗證。本頁的步驟說明如何取得管理員叢集設定檔中 privateRegistry 區段所需的位址、憑證和 CA 憑證。

設定憑證檔案

  1. 如果尚未設定登錄檔的驗證機制,請按照「為 Docker 設定 Artifact Registry 驗證機制」一文的步驟,使用服務帳戶設定驗證機制。您必須使用服務帳戶和 JSON 金鑰檔案進行驗證。

  2. 建立憑證設定檔 admin-creds.yaml,如以下範例所示。username 必須為 "_json_key"。只要與您要新增至 privateRegistry.entry 欄位的值相符,name 欄位可以使用任何值。

    apiVersion: v1
    kind: "CredentialFile"
    items:
    - name: "private-registry-creds"
      username: "_json_key"
      password:
    
  3. 在登錄服務帳戶的 JSON 金鑰檔案所在目錄中,對金鑰檔案執行 cat,輸出內容。

  4. 複製整個 JSON 金鑰內容,然後貼到 password 欄位。請務必以單引號括住 JSON 金鑰內容,因為內容包含雙引號。例如:

    apiVersion: v1
    kind: "CredentialFile"
    items:
    - name: "private-registry-creds"
      username: "_json_key"
      password: '{
    "type": "service_account",
    "project_id": "example-project-12345",
    "private_key_id": "d2661ccb21e686658c6552cf1e0166b857091b2e",
    "private_key": "-----BEGIN PRIVATE ... -----END PRIVATE KEY-----\n",
    "client_email": "test-537@example-project-12345.iam.gserviceaccount.com",
    "client_id": "111772984510027821291",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/test-537%40example-project-12345.iam.gserviceaccount.com",
    "universe_domain": "googleapis.com"
    }
    '
    

在管理員叢集設定檔中設定 privateRegistry

如要使用私人登錄檔,您必須在建立管理員叢集時設定 privateRegistry 區段。叢集建立完成後,您就無法變更 privateRegistry.address,但其他設定可以變更,且您可視需要更新。

  1. 執行下列指令來取得登錄檔位址:

    gcloud artifacts repositories describe REGISTRY_NAME \
        --project=PROJECT_ID
        --location=REGION
    

    更改下列內容:

    • REGISTRY_NAME:登錄檔的名稱。
    • PROJECT_ID:建立登錄檔的專案 ID。
    • LOCATION:建立登錄檔的區域,例如 us-west2

    輸出結果會與下列內容相似:

    Encryption: Google-managed key
    Repository Size: 0.000MB
    cleanupPolicyDryRun: true
    createTime: '2025-01-28T03:27:57.701672Z'
    dockerConfig: {}
    format: DOCKER
    mode: STANDARD_REPOSITORY
    name: projects/example-project-12345/locations/us-west2/repositories/test
    registryUri: us-west2-docker.pkg.dev/example-project-12345/test
    satisfiesPzi: true
    updateTime: '2025-01-28T03:27:57.701672Z'
    vulnerabilityScanningConfig:
      enablementConfig: INHERITED
      enablementState: SCANNING_ACTIVE
      lastEnableTime: '2025-01-28T03:27:49.385246079Z'
    

    在輸出中,使用 registryUri 值做為 privateRegistry.address

  2. 執行下列指令,擷取 Artifact Registry 端點的 CA 憑證,並儲存至名為 ar-ca.pem 的檔案:

    true | openssl s_client -connect REGION-docker.pkg.dev:443 -showcerts 2>/dev/null| sed -ne '/-BEGIN/,/-END/p' > ar-ca.pem
    
  3. 按照下列方式填寫「privateRegistry」部分:

    privateRegistry:
      address: "REGISTRY_ADDRESS"
      credentials:
        fileRef:
          path: "CREDENTIAL_FILE_PATH"
          entry: "private-registry-creds"
      caCertPath: "CA_CERT_PATH"
    componentAccessServiceAccountKeyPath: "COMPONENT_ACCESS_KEY_PATH"
    

    更改下列內容:

    • REGISTRY_ADDRESSregistryUri 的值。
    • CREDENTIAL_FILE_PATHadmin-creds.yaml 檔案的完整或相對路徑。
    • CA_CERT_PATHar-ca.pem 檔案的完整或相對路徑。
    • COMPONENT_ACCESS_KEY_PATH:元件存取服務帳戶金鑰檔案的完整或相對路徑。