分享方式:


部署和管理已啟用 Azure Arc 的 Kubernetes 叢集延伸模組

您可以在已啟用 Azure Arc 的 Kubernetes 叢集中建立延伸模組執行個體,設定必要和選擇性參數,包括更新和設定相關選項。 您也可以檢視、列出、更新和刪除延伸模組執行個體。

開始之前,請先閱讀已啟用 Arc 的 Kubernetes 叢集延伸模組的概念概觀,並檢閱目前可用的延伸模組清單

必要條件

  • 最新版本的 Azure CLI

  • 最新版本的 connectedk8sk8s-extension Azure CLI 延伸模組。 執行下列命令來安裝這些 Azure CLI 延伸模組:

    az extension add --name connectedk8s
    az extension add --name k8s-extension
    

    如果已安裝 connectedk8sk8s-extension 延伸模組,請確定它們已使用下列命令更新為最新版本:

    az extension update --name connectedk8s
    az extension update --name k8s-extension
    
  • 具有已啟用 Azure Arc 的現有 Kubernetes 連線叢集,其中至少有一個由作業系統和結構類型 linux/amd64 組成的節點。 如果部署 Flux (GitOps),您可以使用沒有 linux/amd64 節點的 ARM64 型叢集。

建立延伸模組執行個體

若要建立新的延伸模組執行個體,請使用 k8s-extension create,傳入必要參數的值。

此範例會在已啟用 Azure Arc 的 Kubernetes 叢集上建立 Azure 監視器容器深入解析 延伸模組執行個體:

az k8s-extension create --name azuremonitor-containers  --extension-type Microsoft.AzureMonitor.Containers --scope cluster --cluster-name <clusterName> --resource-group <resourceGroupName> --cluster-type connectedClusters

輸出:

{
  "autoUpgradeMinorVersion": true,
  "configurationProtectedSettings": null,
  "configurationSettings": {
    "logAnalyticsWorkspaceResourceID": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationalinsights/workspaces/defaultworkspace-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-eus"
  },
  "creationTime": "2021-04-02T12:13:06.7534628+00:00",
  "errorInfo": {
    "code": null,
    "message": null
  },
  "extensionType": "microsoft.azuremonitor.containers",
  "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/demo/providers/Microsoft.Kubernetes/connectedClusters/demo/providers/Microsoft.KubernetesConfiguration/extensions/azuremonitor-containers",
  "identity": null,
  "installState": "Pending",
  "lastModifiedTime": "2021-04-02T12:13:06.753463+00:00",
  "lastStatusTime": null,
  "name": "azuremonitor-containers",
  "releaseTrain": "Stable",
  "resourceGroup": "demo",
  "scope": {
    "cluster": {
      "releaseNamespace": "azuremonitor-containers"
    },
    "namespace": null
  },
  "statuses": [],
  "systemData": null,
  "type": "Microsoft.KubernetesConfiguration/extensions",
  "version": "2.8.2"
}

注意

服務無法保留敏感性資訊超過 48 小時。 如果已啟用 Azure Arc 的 Kubernetes 代理程式沒有網路連線超過 48 小時,而且無法判斷是否要在叢集上建立延伸模組,則延伸模組會轉換為 Failed 狀態。 一旦發生這種情況,您必須再次執行 k8s-extension create,才能建立全新的延伸模組 Azure 資源。

Azure 監視器容器深入解析是單一延伸模組 (每個叢集只需要一個)。 您必須清除任何先前 Azure 監視器容器深入解析的 Helm 圖表安裝 (不包括延伸模組),再透過延伸模組安裝相同的內容。 請遵循執行 az k8s-extension create 前,刪除 Helm 圖表的指示。

必要參數

使用 az k8s-extension create 來建立延伸模組執行個體時,需要下列參數。

參數名稱 描述
--name 擴充功能執行個體的名稱
--extension-type 選取您想要在叢集上安裝的延伸模組類型。 例如:Microsoft.AzureMonitor.Containers 和 microsoft.azuredefender.kubernetes
--scope 延伸模組的安裝範圍clusternamespace
--cluster-name 延伸模組執行個體必須建立在已啟用 Azure Arc 的 Kubernetes 資源的名稱中
--resource-group 包括已啟用 Azure Arc 的 Kubernetes 資源的資源群組
--cluster-type 必須建立擴充功能執行個體的叢集類型。 在大部分情況下,請使用對應至已啟用 Azure Arc 的 Kubernetes 叢集的 connectedClusters

選擇性參數

視需要針對您的案例使用其中一或多個選擇性參數,以及必要的參數。

注意

您可以選擇將 延伸模組執行個體自動升級至最新的次要和修補程式版本,方法是將 auto-upgrade-minor-version 設定為 true,或者您可以改為使用 --version 參數手動設定延伸模組執行個體的版本。 建議您針對次要和修補程式版本啟用自動升級,以便您一律擁有最新的安全性修補程式和功能。

因為主要版本升級可能包含中斷性變更,因此不支援自動升級新主要版本的延伸模組執行個體。 您可以選擇何時將延伸模組執行個體手動升級至新的主要版本。

參數名稱 描述
--auto-upgrade-minor-version 判斷延伸模組次要版本是否自動升級的布林值屬性。 預設設定是 true。 如果此參數設定為 true,則無法設定 version 參數,因為版本將會動態更新。 如果設定為 false,則延伸模組不會自動升級,即使是修補程式版本也一樣。
--version 要安裝的擴充功能版本 (要釘選擴充功能執行個體的特定版本)。 如果 auto-upgrade-minor-version 設定為 true,則不得提供。
--configuration-settings 可傳遞至擴充功能以控制其功能的設定。 在參數名稱之後,其會以空格分隔 key=value 組的形式傳入。 如果在命令中使用此參數,則 --configuration-settings-file 不能在相同的命令中使用。
--configuration-settings-file JSON 檔案的路徑,其中包含要用來將組態設定傳遞至延伸模組的 key=value 組。 如果在命令中使用此參數,則 --configuration-settings 不能在相同的命令中使用。
--configuration-protected-settings 無法使用 GET API 呼叫或 az k8s-extension show 命令來擷取的設定。 通常用來傳入敏感性設定。 在參數名稱之後,其會以空格分隔 key=value 組的形式傳入。 如果在命令中使用此參數,則 --configuration-protected-settings-file 不能在相同的命令中使用。
--configuration-protected-settings-file JSON 檔案的路徑,其中包含要用來將敏感性設定傳遞至延伸模組的 key=value 組。 如果在命令中使用此參數,則 --configuration-protected-settings 不能在相同的命令中使用。
--release-namespace 這個參數表示將在發行版本中建立的命名空間。 只有在 scope 設定為 cluster 時才相關。
--release-train 延伸模組作者可以在各種發行訓練 (例如 StablePreview 等) 中發佈版本。如果未明確設定此參數,則會使用 Stable 作為預設值。
--target-namespace 表示將在發行版本中建立的命名空間。 為此擴充功能執行個體建立的系統帳戶權限會限制為此命名空間。 只有在 scope 設定為 namespace 時才相關。

顯示延伸模組詳細資料

若要檢視目前已安裝延伸模組執行個體的詳細資料,請使用 k8s-extension show 並傳入必要參數的值。

az k8s-extension show --name azuremonitor-containers --cluster-name <clusterName> --resource-group <resourceGroupName> --cluster-type connectedClusters

輸出:

{
  "autoUpgradeMinorVersion": true,
  "configurationProtectedSettings": null,
  "configurationSettings": {
    "logAnalyticsWorkspaceResourceID": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationalinsights/workspaces/defaultworkspace-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-eus"
  },
  "creationTime": "2021-04-02T12:13:06.7534628+00:00",
  "errorInfo": {
    "code": null,
    "message": null
  },
  "extensionType": "microsoft.azuremonitor.containers",
  "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/demo/providers/Microsoft.Kubernetes/connectedClusters/demo/providers/Microsoft.KubernetesConfiguration/extensions/azuremonitor-containers",
  "identity": null,
  "installState": "Installed",
  "lastModifiedTime": "2021-04-02T12:13:06.753463+00:00",
  "lastStatusTime": "2021-04-02T12:13:49.636+00:00",
  "name": "azuremonitor-containers",
  "releaseTrain": "Stable",
  "resourceGroup": "demo",
  "scope": {
    "cluster": {
      "releaseNamespace": "azuremonitor-containers"
    },
    "namespace": null
  },
  "statuses": [],
  "systemData": null,
  "type": "Microsoft.KubernetesConfiguration/extensions",
  "version": "2.8.2"
}

列出叢集上安裝的所有擴充功能

若要檢視叢集上安裝的所有延伸模組清單,請使用 k8s-extension list 並傳入必要參數的值。

az k8s-extension list --cluster-name <clusterName> --resource-group <resourceGroupName> --cluster-type connectedClusters

輸出:

[
  {
    "autoUpgradeMinorVersion": true,
    "creationTime": "2020-09-15T02:26:03.5519523+00:00",
    "errorInfo": {
      "code": null,
      "message": null
    },
    "extensionType": "Microsoft.AzureMonitor.Containers",
    "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRg/providers/Microsoft.Kubernetes/connectedClusters/myCluster/providers/Microsoft.KubernetesConfiguration/extensions/myExtInstanceName",
    "identity": null,
    "installState": "Pending",
    "lastModifiedTime": "2020-09-15T02:48:45.6469664+00:00",
    "lastStatusTime": null,
    "name": "myExtInstanceName",
    "releaseTrain": "Stable",
    "resourceGroup": "myRG",
    "scope": {
      "cluster": {
        "releaseNamespace": "myExtInstanceName1"
      }
    },
    "statuses": [],
    "type": "Microsoft.KubernetesConfiguration/extensions",
    "version": "0.1.0"
  },
  {
    "autoUpgradeMinorVersion": true,
    "creationTime": "2020-09-02T00:41:16.8005159+00:00",
    "errorInfo": {
      "code": null,
      "message": null
    },
    "extensionType": "microsoft.azuredefender.kubernetes",
    "id": "/subscriptions/0e849346-4343-582b-95a3-e40e6a648ae1/resourceGroups/myRg/providers/Microsoft.Kubernetes/connectedClusters/myCluster/providers/Microsoft.KubernetesConfiguration/extensions/defender",
    "identity": null,
    "installState": "Pending",
    "lastModifiedTime": "2020-09-02T00:41:16.8005162+00:00",
    "lastStatusTime": null,
    "name": "microsoft.azuredefender.kubernetes",
    "releaseTrain": "Stable",
    "resourceGroup": "myRg",
    "scope": {
      "cluster": {
        "releaseNamespace": "myExtInstanceName2"
      }
    },
    "type": "Microsoft.KubernetesConfiguration/extensions",
    "version": "0.1.0"
  }
]

更新擴充功能執行個體

注意

請參閱特定延伸模組類型的文件,以了解 --configuration-settings--configuration-protected-settings 中能夠更新的特定設定。 針對 --configuration-protected-settings,即使只更新一個設定,也要提供所有設定。 如果省略這其中任何設定,即會將那些設定視為已淘汰並加以刪除。

若要更新現有的延伸模組執行個體,請使用 k8s-extension update 並傳入必要和選擇性參數的值。 必要和選擇性參數與用來建立延伸模組執行個體的參數略有不同。

此範例會將 Azure Machine Learning 延伸模組執行個體的 auto-upgrade-minor-version 設定更新為 true

az k8s-extension update --name azureml --extension-type Microsoft.AzureML.Kubernetes --scope cluster --cluster-name <clusterName> --resource-group <resourceGroupName> --auto-upgrade-minor-version true --cluster-type managedClusters

適用於更新的必要參數

參數名稱 描述
--name 擴充功能執行個體的名稱
--cluster-name 必須建立延伸模組執行個體的叢集名稱
--resource-group 包含叢集的資源群組
--cluster-type 必須建立擴充功能執行個體的叢集類型。 針對已啟用 Azure Arc 的 Kubernetes 叢集,請使用 connectedClusters。 針對 AKS 叢集,請使用 managedClusters

用於更新的選擇性參數

參數名稱 描述
--auto-upgrade-minor-version 指定延伸模組次要版本是否自動升級的布林值屬性。 預設設定是 true。 如果此參數設定為 true,則無法設定 version 參數,因為版本將會動態更新。 如果設定為 false,則延伸模組不會自動升級,即使是修補程式版本也一樣。
--version 要安裝的擴充功能版本 (要釘選擴充功能執行個體的特定版本)。 如果 auto-upgrade-minor-version 設定為 true,則不得提供。
--configuration-settings 可傳遞至擴充功能以控制其功能的設定。 在參數名稱之後,其會以空格分隔 key=value 組的形式傳入。 如果在命令中使用此參數,則 --configuration-settings-file 不能在相同的命令中使用。 只需要提供需更新的設定。 所提供的設定會取代為所指定的值。
--configuration-settings-file JSON 檔案的路徑,其中包含要用來將組態設定傳遞至延伸模組的 key=value 組。 如果在命令中使用此參數,則 --configuration-settings 不能在相同的命令中使用。
--configuration-protected-settings 無法使用 GET API 呼叫或 az k8s-extension show 命令來擷取的設定。 通常用來傳入敏感性設定。 在參數名稱之後,其會以空格分隔 key=value 組的形式傳入。 如果在命令中使用此參數,則 --configuration-protected-settings-file 不能在相同的命令中使用。 當您更新受保護的設定時,應該指定所有受保護的設定。 如果省略這其中任何設定,即會將那些設定視為已淘汰並加以刪除。
--configuration-protected-settings-file JSON 檔案的路徑,其中包含要用來將敏感性設定傳遞至延伸模組的 key=value 組。 如果在命令中使用此參數,則 --configuration-protected-settings 不能在相同的命令中使用。
--scope 延伸模組的安裝範圍 - clusternamespace
--release-train 延伸模組作者可以在各種發行訓練 (例如 StablePreview 等) 中發佈版本。如果未明確設定此參數,則會使用 Stable 作為預設值。

升級延伸模組執行個體

如先前所述,如果您將 auto-upgrade-minor-version 設定為 true,則在發行新的次要版本時,會自動升級延伸模組。 在大部分情況下,建議啟用自動升級。 如果您將 auto-upgrade-minor-version 設定為 false,則如果您想要較新版本,則必須手動升級延伸模組。

如果要取得延伸模組的新主要執行個體,則也需要手動升級。 您可以選擇何時升級,以避免使用主要版本升級的任何非預期中斷性變更。

若要手動升級延伸模組執行個體,請使用 k8s-extension update 並設定 version 參數來指定版本。

此範例會將 Azure Machine Learning 延伸模組執行個體更新為 x.y.z 版:

az k8s-extension update --cluster-name <clusterName> --resource-group <resourceGroupName> --cluster-type connectedClusters --name azureml --version x.y.z

刪除延伸模組執行個體

若要刪除叢集上的延伸模組執行個體,請使用 k8s-extension delete 並傳入必要參數的值:

az k8s-extension delete --name azuremonitor-containers --cluster-name <clusterName> --resource-group <resourceGroupName> --cluster-type connectedClusters

注意

代表此擴充功能的 Azure 資源會立即刪除。 只有在 Kubernetes 叢集上執行的代理程式具有網路連線,並且可以再次連線到 Azure 服務以擷取所需的狀態時,才會刪除與此擴充功能建立關聯的叢集 Helm 版本。

下一步