AKS Edge Essentials 的其他組態和腳本
本文提供連線到 Azure Arc 的替代方式,其適用於透過 Proxy 連線的叢集。
使用 Proxy 將 AKS Edge Essentials 叢集連線到 Arc
必要條件
- 具有擁有者角色或參與者和使用者存取系統管理員角色組合的 Azure 訂用帳戶。 您可以流覽至您的訂用帳戶,選取 Azure 入口網站 左側的 [訪問控制],然後選取 [檢視我的存取權],以檢查您的存取層級。 如需管理資源群組的詳細資訊,請參閱 Azure Resource Manager 檔。
- 在 Azure 訂用帳戶中啟用所有必要的資源提供者,例如 Microsoft.HybridCompute、Microsoft.GuestConfiguration、Microsoft.HybridConnectivity、Microsoft.Kubernetes 和 Microsoft.KubernetesConfiguration。
- 建立並驗證 AKS Edge Essentials Azure 資源的資源群組。
注意
您必須具有參與者角色,才能刪除資源群組內的資源。 與 Arc 中斷連線的命令將會失敗,而不需要此角色指派。
步驟 1:設定 Azure 連線的叢集
如果您先前尚未這麼做,請下載 Azure/AKS-Edge GitHub 存放庫。 流覽至 [ 程序代碼] 索引標籤,然後按兩下 [ 下載 Zip ] 按鈕,將存放庫下載為 .zip 檔案。 將 .zip 檔案解壓縮到本機資料夾。
在 本節下方
Azure
的 aide-userconfig.json 檔案中提供 Azure 訂用帳戶的詳細數據,如下表所述。 若要使用已啟用 Azure Arc 的 Kubernetes 成功連線到 Azure,您需要服務主體,以提供 Azure 上資源的角色型存取權。 如果您已經有服務主體標識碼和密碼,則可以更新aide-userconfig.json檔案中的所有字段。 如果您沒有服務主體,則可以提供名稱,而下一個步驟中的腳本會建立一個,並填入Auth
區段。屬性 值類型 描述 Azure.ClusterName
string 為您的叢集提供名稱。 根據預設, hostname_cluster
是所使用的名稱。Azure.Location
字串 資源群組的位置。 選擇最接近部署的位置。 Azure.SubscriptionName
字串 您的訂閱名稱。 Azure.SubscriptionId
GUID 您的訂用帳戶識別碼。 在 Azure 入口網站 中,選取您所使用的訂用帳戶,然後將訂用帳戶標識符字串複製/貼到 JSON 中。 Azure.TenantId
GUID 您的租用戶識別碼。 在 Azure 入口網站 中,搜尋 “Azure Active Directory”,這應該會帶您前往 [默認目錄] 頁面。 從這裡,您可以將租使用者標識符字串複製/貼到 JSON 檔案中。 Azure.ResourceGroupName
字串 用來裝載 AKS 邊緣程式集 Azure 資源的 Azure 資源群組名稱。 您可以使用現有的資源群組,或如果您新增名稱,系統就會為您建立一個資源群組。 Azure.ServicePrincipalName
字串 Azure 服務主體名稱。 Azure.Auth.ServicePrincipalId
GUID 做為認證之 Azure 服務主體的 AppID。 AKS Edge Essentials 會使用此服務主體將叢集連線到 Arc。您可以使用現有的服務主體,或如果您新增名稱,系統會在下一個步驟中為您建立一個。 Azure.Auth.Password
字串 Azure 服務主體要作為認證的密碼(以純文本表示)。 AksEdgeConfigFile
字串 AKS Edge Essentials 組態的檔名 ( aksedge-config.json
)。 腳本會AksEdgeAzureSetup.ps1
使用必要資訊來更新Arc
此 JSON 檔案的 區段。注意
每個 Azure 訂用帳戶只需要執行此程式一次,而且不需要針對每個 Kubernetes 叢集重複。
執行或按兩下 AksEdgePrompt.cmd 檔案,以開啟已載入所需模組的提升許可權 PowerShell 視窗。 計算機資訊和已安裝的軟體版本概觀隨即顯示。
在 tools\scripts\AksEdgeAzureSetup 資料夾中執行 AksEdgeAzureSetup.ps1 腳本。 此文稿會提示您使用認證登入,以設定您的 Azure 訂用帳戶:
# prompts for interactive login for service principal creation with Contributor role at resource group level ..\tools\scripts\AksEdgeAzureSetup\AksEdgeAzureSetup.ps1 .\aide-userconfig.json -spContributorRole # (or) alternative option # Prompts for interactive login for service principal creation with minimal privileges ..\tools\scripts\AksEdgeAzureSetup\AksEdgeAzureSetup.ps1 .\aide-userconfig.json
使用 AksEdgeAzureSetup-Test.ps1 腳本,確定認證有效。 此文稿會使用新的服務主體認證登入 Azure,並檢查 Azure 資源的狀態:
# Test the credentials ..\tools\scripts\AksEdgeAzureSetup\AksEdgeAzureSetup-Test.ps1 .\aide-userconfig.json
步驟 2:將您的叢集連線到 Azure
使用
Read-AideUserConfig
將 JSON 組態載入 AksEdgeShell,並確認值已使用Get-AideUserConfig
更新。 或者,您可以重新開啟 AksEdgePrompt.cmd ,以使用更新的 JSON 組態:Read-AideUserConfig Get-AideUserConfig
重要
每次修改aide-userconfig.json、執行
Read-AideUserConfig
以重載或關閉並重新開啟AksEdgePrompt.cmd。執行
Initialize-AideArc
。 這會安裝 Azure CLI(如果尚未安裝)、使用指定的認證登入 Azure,並驗證 Azure 設定(資源提供者和資源群組狀態):Initialize-AideArc
執行
Connect-AideArc
以安裝和將主計算機連線到已啟用 Arc 的伺服器,並將現有的叢集連線至已啟用 Arc 的 Kubernetes:# Connect Arc-enabled server and Arc-enabled Kubernetes Connect-AideArc
或者,您可以針對已啟用 Arc 的伺服器,以及
Connect-AideArcKubernetes
啟用 Arc 的 Kubernetes,個別連接Connect-AideArcServer
它們:# Connect Arc-enabled server Connect-AideArcServer # Connect Arc-enabled Kubernetes Connect-AideArcKubernetes
注意
此步驟最多可能需要 10 分鐘的時間,且 PowerShell 可能會卡在「建立 Azure 已連線 Kubernetes」 上
your cluster name
。 PowerShell 命令會在程式完成時輸出True
並返回提示。 持有人令牌會儲存在 tools 資料夾中servicetoken.txt。
步驟 3:檢視 Azure 上的叢集
在左側面板中,選取 [Kubernetes 資源] 底下的 [命名空間] 刀鋒視窗 (預覽):
若要檢視 Kubernetes 資源,您需要持有人令牌:
在 PowerShell 視窗中,執行
Get-AksEdgeManagedServiceToken
,複製完整的字串,並將其貼到 Azure 入口網站:現在您可以檢視叢集上的資源。 下圖顯示 [ 工作負載] 刀鋒視窗,顯示與
kubectl get pods --all-namespaces
相同的 :
使用 Proxy 時中斷 AKS Edge Essentials 叢集與 Arc 的連線
執行 Disconnect-AideArc
以中斷與已啟用 Arc 的伺服器和已啟用 Arc 的 Kubernetes 的連線:
# Disconnect Arc-enabled server and Arc-enabled Kubernetes
Disconnect-AideArc
或者,您可以針對已啟用 Arc 的伺服器和Connect-AideArcKubernetes
已啟用 Arc 的 Kubernetes,個別將其Connect-AideArcServer
中斷連線:
# Disconnect Arc-enabled server
Disconnect-AideArcServer
# Disconnect Arc-enabled Kubernetes
Disconnect-AideArcKubernetes
將主電腦連線至Arc
您可以針對已開啟 Arc 的伺服器連線
Connect-AideArcServer
主電腦:# Connect Arc-enabled server Connect-AideArcServer
若要將主電腦與 Arc 中斷連線,請針對已啟用 Arc 的伺服器使用
Disconnect-AideArcServer
:# Disconnect Arc-enabled server Disconnect-AideArcServer
您也可以依照這裡的步驟卸載Arc for Server代理程式。 如需完整清除 Azure 入口網站,請刪除您為此範例建立的服務主體和資源群組。