使用 PowerShell 模块在 Azure Kubernetes 服务上配置 gMSA
在本部分中,我们将介绍如何使用 AKS PowerShell 模块上的 gMSA 在 Azure Kubernetes 服务上设置 gMSA。 以下步骤假定已在 AKS PowerShell 模块上安装 gMSA、连接到 AKS 群集并提供所需的参数。 如果尚未这样做,请确保按照本教程的第一部分 中的步骤进行操作。
确认 AKS 群集已正确配置 gMSA 功能
可能已针对 gMSA 配置 AKS 群集,也可能还未配置。 若要验证群集是否准备好使用 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"]
授予 AKV 对 AKS Windows 主机的访问权限
# 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 节点上部署工作负荷。
下一步
使用 PowerShell 模块 在 AKS 上验证 gMSA