使用 PowerShell 模組在 Azure Kubernetes Service 上設定 gMSA
在本節中,我們將討論如何使用 AKS PowerShell 模組上的 gMSA 在 Azure Kubernetes Service 上設定 gMSA。 下列步驟假設您已在 AKS PowerShell 模組上安裝 gMSA、連線到 AKS 叢集,並提供必要的參數。 如果您尚未這麼做,請務必先按照本教學課程的第一部分的步驟進行操作。
確認 AKS 叢集已正確設定 gMSA 功能
您的 AKS 叢集可能或可能尚未針對 gMSA 進行設定。 若要驗證叢集是否已準備好使用 gMSA,請執行下列命令:
Confirm-AksGMSAConfiguration `
-AksResourceGroupName $params["aks-cluster-rg-name"] `
-AksClusterName $params["aks-cluster-name"] `
-AksGMSADomainDnsServer $params["domain-dns-server"] `
-AksGMSARootDomainName $params["domain-fqdn"]
設定叢集之後,您可以設定 gMSA 運作所需的其餘基礎結構。
設定 Active Directory 環境
準備 Active Directory 的第一個步驟是確保已設定密鑰散發系統。 針對此步驟,需要在域控制器上以具有適當委派的認證來執行命令。 此工作可以委派給已授權的人員。
從網域控制器執行下列命令以啟用根金鑰:
針對生產環境:
# You will need to wait 10 hours before the KDS root key is
# replicated and available for use on all domain controllers.
Add-KdsRootKey -EffectiveImmediately
針對測試環境:
# For single-DC test environments ONLY.
Add-KdsRootKey -EffectiveTime (Get-Date).AddHours(-10)
針對下列命令,您可以在域控制器或遠端 PowerShell 工作階段上執行它們。 如果從域控制器執行,請從命令中移除 「DomainControllerAddress」、“DomainUser” 和 “DomainPassword” 參數。
如果從遠端執行,請確定您的域控制器已設定為遠端管理。
建立標準網域使用者
# Creates the standard domain user.
New-GMSADomainUser `
-Name $params["gmsa-domain-user-name"] `
-Password $params["gmsa-domain-user-password"] `
-DomainControllerAddress $params["domain-controller-address"] `
-DomainAdmin "$($params["domain-fqdn"])\$($params["domain-admin-user-name"])" `
-DomainAdminPassword $params["domain-admin-user-password"]
建立 gMSA
# Creates the gMSA account, and it authorizes only the standard domain user.
New-GMSA `
-Name $params["gmsa-name"] `
-AuthorizedUser $params["gmsa-domain-user-name"] `
-DomainControllerAddress $params["domain-controller-address"] `
-DomainAdmin "$($params["domain-fqdn"])\$($params["domain-admin-user-name"])" `
-DomainAdminPassword $params["domain-admin-user-password"]
設定 Azure Key Vault 和 Azure 使用者指派的受控識別
Azure Key Vault (AKV) 將用來將 Windows 節點所使用的認證儲存在 AKS 上,以與 Active Directory 域控制器通訊。 受控識別 (MI) 將用來為您的 Windows 節點提供適當的 AKV 存取權。
建立 Azure 金鑰保存庫
# The Azure key vault will have a secret with the credentials of the standard
# domain user authorized to fetch the gMSA.
New-GMSAAzureKeyVault `
-ResourceGroupName $params["aks-cluster-rg-name"] `
-Location $params["azure-location"] `
-Name $params["akv-name"] `
-SecretName $params["akv-secret-name"] `
-GMSADomainUser "$($params["domain-fqdn"])\$($params["gmsa-domain-user-name"])" `
-GMSADomainUserPassword $params["gmsa-domain-user-password"]
建立 Azure 使用者指派的受控識別
New-GMSAManagedIdentity `
-ResourceGroupName $params["aks-cluster-rg-name"] `
-Location $params["azure-location"] `
-Name $params["ami-name"]
為 AKS Windows 主機授予 AKV 存取權限
# Appends the user-assigned managed identity to the AKS Windows agent pools given as input parameter.
# Configures the AKV read access policy for the user-assigned managed identity.
Grant-AkvAccessToAksWindowsHosts `
-AksResourceGroupName $params["aks-cluster-rg-name"] `
-AksClusterName $params["aks-cluster-name"] `
-AksWindowsNodePoolsNames $params["aks-win-node-pools-names"] `
-VaultResourceGroupName $params["aks-cluster-rg-name"] `
-VaultName $params["akv-name"] `
-ManagedIdentityResourceGroupName $params["aks-cluster-rg-name"] `
-ManagedIdentityName $params["ami-name"]
使用 RBAC 資源設定 gMSA 認證規格
# Creates the gMSA credential spec.
# Configures the appropriate RBAC resources (ClusterRole and RoleBinding) for the spec.
# Executes AD commands to get the appropriate domain information for the credential spec.
New-GMSACredentialSpec `
-Name $params["gmsa-spec-name"] `
-GMSAName $params["gmsa-name"] `
-ManagedIdentityResourceGroupName $params["aks-cluster-rg-name"] `
-ManagedIdentityName $params["ami-name"] `
-VaultName $params["akv-name"] `
-VaultGMSASecretName $params["akv-secret-name"] `
-DomainControllerAddress $params["domain-controller-address"] `
-DomainUser "$($params["domain-fqdn"])\$($params["gmsa-domain-user-name"])" `
-DomainUserPassword $params["gmsa-domain-user-password"]
在這個階段中,AKS 上的 gMSA 設定已完成。 您現在可以在 Windows 節點上部署工作負載。