快速入門:將現有 Kubernetes 叢集連線至 Azure Arc
使用 Azure CLI 或Azure PowerShell將現有的 Kubernetes 叢集連線至 Azure Arc,開始使用已啟用 Azure Arc 的 Azure Arc。
如需將叢集連線至 Azure Arc 的概念性檢視,請參閱 已啟用 Azure Arc 的 Kubernetes 代理程式概觀。
必要條件
具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶。
Kubernetes 核心概念的基本瞭解。
身分識別 (使用者或服務主體) ,可用來 登入 Azure CLI ,並將叢集連線至 Azure Arc。
重要
- 身分識別必須具有已啟用 Azure Arc 之 Kubernetes 資源類型的「讀取」和「寫入」許可權, (
Microsoft.Kubernetes/connectedClusters
) 。 - 如果將叢集連線到現有的資源群組 (,而不是此身分識別) 建立的新資源群組,則身分識別必須具有該資源群組的「讀取」許可權。
- Kubernetes 叢集 - Azure Arc 上線內建角色可用於此身分識別。 此角色適用于大規模上線,因為它只有將叢集連線至 Azure Arc 所需的細微許可權,而且沒有更新、刪除或修改任何其他叢集或其他 Azure 資源的許可權。
- 身分識別必須具有已啟用 Azure Arc 之 Kubernetes 資源類型的「讀取」和「寫入」許可權, (
安裝 Azure CLI 或升級至最新版本。
安裝最新版的 connectedk8s Azure CLI 擴充功能:
az extension add --name connectedk8s
啟動並執行 Kubernetes 叢集。 如果您沒有叢集,則可以使用下列其中一個選項來建立叢集:
使用適用於 Mac 或 Windows 的 Docker來建立 Kube 叢集
使用叢集 API 的自我管理 Kube 叢集
注意
叢集必須至少有一個作業系統節點和架構類型
linux/amd64
。 尚未支援只有linux/arm64
節點的叢集。
針對將在叢集上部署的 Arc 代理程式,至少有 850 MB 可用,以及使用大約 7% 的單一 CPU 容量。 針對多節點 Kubernetes 叢集環境,Pod 可以在不同的節點上排程。
指向叢集的 kubeconfig 檔案 和內容。
安裝 Helm 3。 確定 Helm 3 版本為 < 3.7.0。
註冊已啟用 Azure Arc 的 Kubernetes 提供者
輸入下列命令:
az provider register --namespace Microsoft.Kubernetes az provider register --namespace Microsoft.KubernetesConfiguration az provider register --namespace Microsoft.ExtendedLocation
監視註冊程序。 註冊最多可能需要 10 分鐘的時間。
az provider show -n Microsoft.Kubernetes -o table az provider show -n Microsoft.KubernetesConfiguration -o table az provider show -n Microsoft.ExtendedLocation -o table
註冊之後,您應該會看到
RegistrationState
這些命名空間的狀態變更為Registered
。
符合網路需求
一般而言,連線需求包括下列原則:
- 除非另有指定,否則所有連線都是 TCP。
- 所有 HTTP 連線都會使用 HTTPS 和 SSL/TLS 搭配正式簽署且可驗證的憑證。
- 除非另有指定,否則所有連線都是輸出的。
若要使用 Proxy,請確認代理程式符合本文中的網路需求。
重要
Azure Arc 代理程式需要下列輸出 URL https://:443
才能運作。
針對 *.servicebus.windows.net
,必須在防火牆和 Proxy 上啟用 Websocket 進行輸出存取。
端點 (DNS) | 描述 |
---|---|
https://management.azure.com |
代理程式連線到 Azure 並註冊叢集的必要專案。 |
https://<region>.dp.kubernetesconfiguration.azure.com |
代理程式的資料平面端點,用來推送狀態以及擷取設定資訊。 |
https://login.microsoftonline.com https://<region>.login.microsoft.com login.windows.net |
擷取和更新 Azure Resource Manager 權杖的必要項目。 |
https://mcr.microsoft.com https://*.data.mcr.microsoft.com |
需要提取 Azure Arc 代理程式的容器映射。 |
https://gbl.his.arc.azure.com |
取得提取系統指派受控識別憑證的區域端點的必要條件。 |
https://*.his.arc.azure.com |
提取系統指派的受控識別憑證所需的憑證。 |
https://k8connecthelm.azureedge.net |
az connectedk8s connect 會使用 Helm 3 在 Kubernetes 叢集上部署 Azure Arc 代理程式。 Helm 用戶端下載需要此端點,以協助部署代理程式 helm 圖表。 |
guestnotificationservice.azure.com *.guestnotificationservice.azure.com sts.windows.net https://k8sconnectcsp.azureedge.net |
針對 叢集連線 ,以及 自訂位置 型案例。 |
*.servicebus.windows.net |
針對 叢集連線 ,以及 自訂位置 型案例。 |
https://graph.microsoft.com/ |
設定 Azure RBAC時需要 |
*.arc.azure.net |
在 Azure 入口網站 中管理已連線的叢集。 |
若要將 *.servicebus.windows.net
萬用字元轉譯為特定端點,請使用 命令:
GET https://guestnotificationservice.azure.com/urls/allowlist?api-version=2020-01-01&location=<region>`.
若要取得區域端點的區域區段,請從 Azure 區功能變數名稱稱中移除所有空格。 例如, 美國東部 2 區域,區功能變數名稱稱為 eastus2
。
例如: san-af-<region>-prod.azurewebsites.net
應 san-af-eastus2-prod.azurewebsites.net
位於美國東部 2 區域。
若要查看所有區域的清單,請執行此命令:
az account list-locations -o table
如需 Azure Arc 功能和已啟用 Azure Arc 服務之網路需求的完整清單,請參閱 Azure Arc 網路需求 (合併) 。
建立資源群組
執行以下命令:
az group create --name AzureArcTest --location EastUS --output table
輸出:
Location Name
---------- ------------
eastus AzureArcTest
連線現有的 Kubernetes 叢集
執行以下命令:
az connectedk8s connect --name AzureArcTest1 --resource-group AzureArcTest
注意
如果您使用服務主體登入 Azure CLI,則必須設定 額外的參數 ,才能在叢集上啟用自訂位置功能。
輸出:
Helm release deployment succeeded
{
"aadProfile": {
"clientAppId": "",
"serverAppId": "",
"tenantId": ""
},
"agentPublicKeyCertificate": "xxxxxxxxxxxxxxxxxxx",
"agentVersion": null,
"connectivityStatus": "Connecting",
"distribution": "gke",
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/AzureArcTest/providers/Microsoft.Kubernetes/connectedClusters/AzureArcTest1",
"identity": {
"principalId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "SystemAssigned"
},
"infrastructure": "gcp",
"kubernetesVersion": null,
"lastConnectivityTime": null,
"location": "eastus",
"managedIdentityCertificateExpirationTime": null,
"name": "AzureArcTest1",
"offering": null,
"provisioningState": "Succeeded",
"resourceGroup": "AzureArcTest",
"tags": {},
"totalCoreCount": null,
"totalNodeCount": null,
"type": "Microsoft.Kubernetes/connectedClusters"
}
提示
上述命令未指定 location 參數,會在與資源群組相同的位置建立已啟用 Azure Arc 的 Kubernetes 資源。 若要在不同的位置建立已啟用 Azure Arc 的 Kubernetes 資源,請在執行 az connectedk8s connect
命令時指定 --location <region>
或 -l <region>
。
重要
在某些情況下,部署可能會因為逾時錯誤而失敗。 如需如何解決此問題的詳細資訊,請參閱 我們的疑難排解指南 。
使用輸出 Proxy 伺服器連線
如果您的叢集位於輸出 Proxy 伺服器後方,則必須透過輸出 Proxy 伺服器路由要求。
設定 Azure CLI 使用輸出 Proxy 伺服器時所需的環境變數:
export HTTP_PROXY=<proxy-server-ip-address>:<port> export HTTPS_PROXY=<proxy-server-ip-address>:<port> export NO_PROXY=<cluster-apiserver-ip-address>:<port>
使用指定的 和
proxy-http
參數執行 connect 命令proxy-https
。 如果您的 Proxy 伺服器同時設定 HTTP 和 HTTPS,請務必用於--proxy-http
HTTP Proxy 和--proxy-https
HTTPS Proxy。 如果您的 Proxy 伺服器只使用 HTTP,您可以針對這兩個參數使用該值。az connectedk8s connect --name <cluster-name> --resource-group <resource-group> --proxy-https https://<proxy-server-ip-address>:<port> --proxy-http http://<proxy-server-ip-address>:<port> --proxy-skip-range <excludedIP>,<excludedCIDR> --proxy-cert <path-to-cert-file>
注意
- 某些網路要求 (例如涉及叢集內服務對服務通訊的網路要求),必須與透過輸出通訊 Proxy 伺服器路由傳送的流量分開。 參數
--proxy-skip-range
可用來以逗號分隔的方式指定 CIDR 範圍和端點,讓從代理程式到這些端點的任何通訊都不會透過輸出 Proxy 進行。 至少應該將叢集中服務的 CIDR 範圍指定為此參數的值。 例如,假設會kubectl get svc -A
傳回服務清單,其中所有服務在 範圍10.0.0.0/16
中都有 ClusterIP 值。 然後,要為其指定的--proxy-skip-range
10.0.0.0/16,kubernetes.default.svc,.svc.cluster.local,.svc
值為 。 --proxy-http
、--proxy-https
和--proxy-skip-range
預期適用于大部分的輸出 Proxy 環境。--proxy-cert
只有在您需要將 Proxy 預期的受信任憑證插入代理程式 Pod 的受信任憑證存放區時, 才 需要 。- 輸出 Proxy 必須設定為允許 Websocket 連線。
對於只需要提供信任憑證且不需要 Proxy 伺服器端點輸入的輸出 Proxy 伺服器, az connectedk8s connect
只要使用指定的輸入即可執行 --proxy-cert
。 如果預期有多個受信任的憑證,可以使用 參數在單一檔案中提供合併的憑證鏈結 --proxy-cert
。
注意
--custom-ca-cert
是--proxy-cert
的別名。 任一個參數都可以交替使用。 在同一個命令中傳遞這兩個參數,將會讓最後一個參數通過。
使用指定的參數執行 connect 命令 --proxy-cert
:
az connectedk8s connect --name <cluster-name> --resource-group <resource-group> --proxy-cert <path-to-cert-file>
確認叢集連線
執行以下命令:
az connectedk8s list --resource-group AzureArcTest --output table
輸出:
Name Location ResourceGroup
------------- ---------- ---------------
AzureArcTest1 eastus AzureArcTest
注意
上線至叢集之後,大約需要大約 5 到 10 分鐘的時間,才會在 Azure 入口網站中已啟用 Azure Arc 的 Kubernetes 資源概觀頁面上呈現叢集中繼資料 (叢集版本、代理程式版本、節點數目等)。
提示
如需連線叢集時針對問題進行疑難排解的說明,請參閱 診斷已啟用 Azure Arc 的 Kubernetes 叢集的連線問題。
檢視適用于 Kubernetes 的 Azure Arc 代理程式
已啟用 Azure Arc 的 Kubernetes 會將一些代理程式 azure-arc
部署到 命名空間。
使用下列專案來檢視這些部署和 Pod:
kubectl get deployments,pods -n azure-arc
確認所有 Pod 都處於
Running
狀態。輸出:
NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/cluster-metadata-operator 1/1 1 1 13d deployment.apps/clusterconnect-agent 1/1 1 1 13d deployment.apps/clusteridentityoperator 1/1 1 1 13d deployment.apps/config-agent 1/1 1 1 13d deployment.apps/controller-manager 1/1 1 1 13d deployment.apps/extension-manager 1/1 1 1 13d deployment.apps/flux-logs-agent 1/1 1 1 13d deployment.apps/kube-aad-proxy 1/1 1 1 13d deployment.apps/metrics-agent 1/1 1 1 13d deployment.apps/resource-sync-agent 1/1 1 1 13d NAME READY STATUS RESTARTS AGE pod/cluster-metadata-operator-9568b899c-2stjn 2/2 Running 0 13d pod/clusterconnect-agent-576758886d-vggmv 3/3 Running 0 13d pod/clusteridentityoperator-6f59466c87-mm96j 2/2 Running 0 13d pod/config-agent-7cbd6cb89f-9fdnt 2/2 Running 0 13d pod/controller-manager-df6d56db5-kxmfj 2/2 Running 0 13d pod/extension-manager-58c94c5b89-c6q72 2/2 Running 0 13d pod/flux-logs-agent-6db9687fcb-rmxww 1/1 Running 0 13d pod/kube-aad-proxy-67b87b9f55-bthqv 2/2 Running 0 13d pod/metrics-agent-575c565fd9-k5j2t 2/2 Running 0 13d pod/resource-sync-agent-6bbd8bcd86-x5bk5 2/2 Running 0 13d
如需這些代理程式的詳細資訊,請參閱 已啟用 Azure Arc 的 Kubernetes 代理程式概觀。
清除資源
您可以使用下列命令,刪除已啟用 Azure Arc 的 Kubernetes 資源、任何相關聯的組態資源, 以及 使用 Azure CLI 在叢集上執行的任何代理程式:
az connectedk8s delete --name AzureArcTest1 --resource-group AzureArcTest
如果刪除程式失敗,請使用下列命令來強制刪除 (新增 -y
,如果您想要略過確認提示) :
az connectedk8s delete -g AzureArcTest1 -n AzureArcTest --force
如果您在建立新的叢集部署時遇到問題, (因為先前建立的資源未完全移除) ,也可以使用此命令。
注意
使用 Azure 入口網站刪除已啟用 Azure Arc 的 Kubernetes 資源會移除任何相關聯的設定資源,但不會移除叢集上執行的任何代理程式。 最佳做法是使用 刪除 az connectedk8s delete
已啟用 Azure Arc 的 Kubernetes 資源,而不是刪除Azure 入口網站中的資源。
下一步
請前往下一篇文章,瞭解如何使用 GitOps 將設定部署至已連線的 Kubernetes 叢集。