共用方式為


快速入門:安裝連接登錄的 Arc 擴充功能

在本快速入門中,您將了解如何使用 CLI UX 搭配預設保護設定來部署已連線登錄檔 Arc 延伸模組,以確保強固的安全性和作業完整性。

已連線登錄檔對於邊緣客戶來說是相當重要的工具,可針對容器化工作負載實現有效率的管理和存取,無論是內部部署還是遠端站台。 藉由與 Azure Arc 容器整合,該服務能確保針對 Kubernetes 型的容器化工作負載提供順暢且統一的生命週期管理體驗。 在已啟用 Arc 的 Kubernetes 叢集上部署已連線登錄檔 Arc 延伸模組,可簡化這些工作負載的管理和存取。

必要條件

  • 設定 Azure CLI (部分機器翻譯) 以連線到 Azure 和 Kubernetes。

  • 使用快速入門建立或使用現有的 Azure Container Registry (ACR)。

  • 啟用專用資料端點以設定 ACR 與已連線登錄檔之間的防火牆存取和通訊。

  • 使用教學課程建立或使用現有的 Azure Kubernetes Service (AKS) 叢集。

  • 遵循快速入門以設定 Kubernetes 叢集與 Azure Arc 之間的連線。

  • 使用 k8s-extension (部分機器翻譯) 命令來管理 Kubernetes 延伸模組。

    az extension add --name k8s-extension
    
  • 在您的訂用帳戶中註冊必要的 Azure 資源提供者 (部分機器翻譯) 並使用已啟用 Azure Arc 的 Kubernetes:

    az provider register --namespace Microsoft.Kubernetes
    az provider register --namespace Microsoft.KubernetesConfiguration
    az provider register --namespace Microsoft.ExtendedLocation
    

    Azure 資源提供者是一組 REST 作業,可啟用特定 Azure 服務的功能。

  • ACR 登錄中的存放庫,以便與已連線登錄檔進行同步處理。

    az acr import --name myacrregistry --source mcr.microsoft.com/mcr/hello-world:latest --image hello-world:latest
    

    hello-world 存放庫會在 ACR 登錄 myacrregistry 中建立,以與已連線登錄檔進行同步處理。

部署使用預設保護設定的已連線登錄檔 Arc 延伸模組

一旦先決條件和必要的條件和元件皆已就緒,請遵循簡化的方法,使用下列設定在已啟用 Arc 的 Kubernetes 叢集上安全地部署已連線登錄檔延伸模組。 這些設定會使用 HTTPS、唯讀、信任散發和 Cert Manager 服務來定義下列設定。 遵循下列步驟以確保能夠成功部署:

  1. 建立已連線登錄檔。(英文)
  2. 部署已連線登錄檔 Arc 延伸模組。(英文)
  3. 確認已連線登錄檔延伸模組的部署情形。(英文)
  4. 部署使用來自已連線登錄檔之映像的 Pod。(英文)

建立已連線登錄檔並與 ACR 進行同步處理

建立已連線登錄檔以與 ACR 進行同步處理的步驟,是部署已連線登錄檔 Arc 延伸模組的基礎步驟。

  1. 建立會與 ACR 登錄進行同步處理的已連線登錄檔:

    若要建立會與資源群組 myconnectedregistry 中的 ACR 登錄 myacrregistry 和存放庫 myresourcegroup 進行同步的已連線登錄檔 hello-world,您可以執行 az acr connected-registry create (部分機器翻譯) 命令:

    az acr connected-registry create --registry myacrregistry \ 
    --name myconnectedregistry \
    --resource-group myresourcegroup \ 
    --repository "hello-world"
    
  • az acr connected-registry create (部分機器翻譯) 命令會搭配指定的存放庫建立已連線登錄檔。
  • az acr connected-registry create (部分機器翻譯) 命令會在存在名為 myscopemap 的同步範圍對應的情況下覆寫動作,並在存在名為 mysynctoken 的同步權杖的情況下覆寫屬性。
  • az acr connected-registry create (部分機器翻譯) 命令會在已連線登錄檔的建立期間驗證專用資料端點,並提供在 ACR 登錄上啟用專用資料端點的命令。

將已連線登錄檔 Arc 延伸模組部署到已啟用 Arc 的 Kubernetes 叢集的上方

藉由部署已連線登錄檔 Arc 延伸模組,您可以將容器映像和其他 Open Container Initiative (OCI) 成品與您的 ACR 登錄同步處理。 該部署可協助加快對登錄成品的存取,並實現進階案例的建置。 延伸模組部署可確保已連線登錄檔與叢集內所有用戶端節點之間的安全信任散發,並且會安裝適用於傳輸層安全性 (TLS) 加密的憑證管理員服務。

  1. 產生連接字串和受保護的設定 JSON 檔案

    若要安全地部署已連線登錄檔延伸模組,請產生連接字串,包括新的密碼、傳輸通訊協定,並使用 protected-settings-extension.json (部分機器翻譯) 命令建立延伸模組部署所需的 檔案:

    cat << EOF > protected-settings-extension.json
    {
      "connectionString": "$(az acr connected-registry get-settings \
      --name myconnectedregistry \
      --registry myacrregistry \
      --parent-protocol https \
      --generate-password 1 \
      --query ACR_REGISTRY_CONNECTION_STRING --output tsv --yes)"
    }
    EOF

注意

cat 和 echo 命令會使用連接字串詳細資料建立 protected-settings-extension.json 檔案,將連接字串的內容插入 protected-settings-extension.json 檔案,此為延伸模組部署的必要步驟。 az acr connected-registry get-settings (部分機器翻譯) 命令會產生連接字串,包括新密碼和傳輸通訊協定規格的建立。

  1. 部署已連線登錄檔延伸模組

    使用 az k8s-extension create (部分機器翻譯) 命令,使用指定的設定詳細資料部署已連線登錄檔延伸模組:

  az k8s-extension create --cluster-name myarck8scluster \ 
  --cluster-type connectedClusters \
  --extension-type Microsoft.ContainerRegistry.ConnectedRegistry \
  --name myconnectedregistry \
  --resource-group myresourcegroup \ 
  --config service.clusterIP=192.100.100.1 \ 
  --config-protected-file protected-settings-extension.json  
  • az k8s-extension create (部分機器翻譯) 命令會使用提供的設定參數和受保護的設定檔,在 Kubernetes 叢集上部署已連線登錄檔延伸模組。
  • 其可確保已連線登錄檔與叢集內所有用戶端節點之間的安全信任散發,並安裝適用於傳輸層安全性 (TLS) 加密的憑證管理員服務。
  • clusterIP 必須來自 AKS 叢集子網路 IP 範圍。 service.clusterIP 參數會指定叢集內已連線登錄檔服務的 IP 位址。 請務必在 Kubernetescluster 的有效服務 IP 範圍內設定 service.clusterIP 。 確定針對 service.clusterIP 指定的 IP 位址落在叢集初始設定期間定義的指定服務 IP 範圍內,此設定通常位於叢集的網路設定中。 service.clusterIP如果 不在此範圍內,則必須更新為同時在有效範圍內且目前未由另一個服務使用的IP位址。

確認已連線登錄檔延伸模組的部署情形

若要確認已啟用 Arc 的 Kubernetes 叢上已連線登錄檔延伸模組的部署情形,請遵循下列步驟:

  1. 驗證部署狀態

    執行 az k8s-extension show (部分機器翻譯) 命令來檢查已連線登錄檔延伸模組的部署狀態:

  az k8s-extension show --name myconnectedregistry \ 
  --cluster-name myarck8scluster \
  --resource-group myresourcegroup \
  --cluster-type connectedClusters

範例輸出

    {
    "aksAssignedIdentity": null,
    "autoUpgradeMinorVersion": true,
    "configurationProtectedSettings": {
      "connectionString": ""
    },
    "configurationSettings": {
      "pvc.storageClassName": "standard",
      "pvc.storageRequest": "250Gi",
      "service.clusterIP": "[your service cluster ip]"
    },
    "currentVersion": "0.11.0",
    "customLocationSettings": null,
    "errorInfo": null,
    "extensionType": "microsoft.containerregistry.connectedregistry",
    "id": "/subscriptions/[your subscription id]/resourceGroups/[your resource group name]/providers/Microsoft.Kubernetes/connectedClusters/[your arc cluster name]/providers/Microsoft.KubernetesConfiguration/extensions/[your extension name]",
    "identity": {
      "principalId": "[identity principal id]",
      "tenantId": null,
      "type": "SystemAssigned"
    },
    "isSystemExtension": false,
    "name": "[your extension name]",
    "packageUri": null,
    "plan": null,
    "provisioningState": "Succeeded",
    "releaseTrain": "preview",
    "resourceGroup": "[your resource group]",
    "scope": {
      "cluster": {
        "releaseNamespace": "connected-registry"
      },
      "namespace": null
    },
    "statuses": [],
    "systemData": {
      "createdAt": "2024-07-12T18:17:51.364427+00:00",
      "createdBy": null,
      "createdByType": null,
      "lastModifiedAt": "2024-07-12T18:22:42.156799+00:00",
      "lastModifiedBy": null,
      "lastModifiedByType": null
    },
    "type": "Microsoft.KubernetesConfiguration/extensions",
    "version": null
  }
  1. 驗證已連線登錄檔的狀態 (Status) 和狀態 (State)

    針對每個已連線登錄檔,您可以使用 az acr connected-registry list (部分機器翻譯) 命令來檢視已連線登錄檔的狀態 (Status) 和狀態 (State):

        az acr connected-registry list --registry myacrregistry \
        --output table
    

範例輸出

    | NAME | MODE | CONNECTION STATE | PARENT | LOGIN SERVER | LAST SYNC(UTC) |
    |------|------|------------------|--------|--------------|----------------|
    | myconnectedregistry | ReadWrite | online | myacrregistry | myacrregistry.azurecr.io | 2024-05-09 12:00:00 |
    | myreadonlyacr | ReadOnly | offline | myacrregistry | myacrregistry.azurecr.io | 2024-05-09 12:00:00 |
  1. 驗證特定已連線登錄檔詳細資料

    如需特定已連線登錄檔的詳細資料,請使用 az acr connected-registry show (部分機器翻譯) 命令:

  az acr connected-registry show --registry myacrregistry \
  --name myreadonlyacr \ 
  --output table

範例輸出

   | NAME                | MODE      | CONNECTION STATE | PARENT        | LOGIN SERVER             | LAST SYNC(UTC)      | SYNC SCHEDULE | SYNC WINDOW       |
   | ------------------- | --------- | ---------------- | ------------- | ------------------------ | ------------------- | ------------- | ----------------- |
   | myconnectedregistry | ReadWrite | online           | myacrregistry | myacrregistry.azurecr.io | 2024-05-09 12:00:00 | 0 0 * * *     | 00:00:00-23:59:59 |
  • az k8s-extension show (部分機器翻譯) 命令會驗證延伸模組部署的狀態。
  • 此命令也會提供已連線登錄檔的連線狀態、上次同步處理、同步窗口、同步排程等詳細資料。

部署使用來自已連線登錄檔之映像的 Pod

若要部署使用來自叢集內已連線登錄檔之映像的 Pod,必須從叢集節點本身執行作業。 執行下列步驟:

  1. 在叢集中建立祕密,以向已連線登錄檔進行驗證:

執行 kubectl create secret docker-registry (英文) 命令以在叢集中建立祕密,以向已連線登錄檔進行驗證:

kubectl create secret docker-registry regcred --docker-server=192.100.100.1 --docker-username=mytoken --docker-password=mypassword
  1. 使用已連線登錄檔的 service.clusterIP 位址 192.100.100.1,以及映像名稱 hello-world 搭配標籤 latest,部署使用來自已連線登錄檔之所需映像的 Pod:

    kubectl apply -f - <<EOF
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: hello-world-deployment
      labels:
        app: hello-world
    spec:
      selector:
        matchLabels:
          app: hello-world
      replicas: 1
      template:
        metadata:
          labels:
            app: hello-world
        spec:
          imagePullSecrets:
            - name: regcred
          containers:
            - name: hello-world
              image: 192.100.100.1/hello-world:latest
    EOF
    

清除資源

藉由刪除部署的已連線登錄檔延伸模組,您可以移除對應的已連線登錄檔 Pod 與組態設定。

  1. 刪除已連線登錄檔延伸模組

    執行 az k8s-extension delete (部分機器翻譯) 命令來刪除已連線登錄檔延伸模組:

    az k8s-extension delete --name myconnectedregistry 
    --cluster-name myarcakscluster \ 
    --resource-group myresourcegroup \ 
    --cluster-type connectedClusters
    

藉由刪除部署的已連線登錄檔,您可以移除已連線登錄檔雲端執行個體與其設定詳細資料。

  1. 刪除已連線登錄檔

    執行 az acr connected-registry delete (部分機器翻譯) 命令來刪除已連線登錄檔:

    az acr connected-registry delete --registry myacrregistry \
    --name myconnectedregistry \
    --resource-group myresourcegroup 
    

下一步