你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
AKS 托管的 Azure Active Directory 集成
AKS 托管的 Azure Active Directory (Azure AD) 集成简化了 Azure AD 集成过程。 以前,你需要创建客户端和服务器应用,并且 Azure AD 租户必须授予“目录读取”权限。 现在,AKS 资源提供程序将为你管理客户端和服务器应用。
群集管理员可以根据用户的标识或目录组成员身份来配置 Kubernetes 基于角色的访问控制 (Kubernetes RBAC)。 使用 OpenID Connect 向 AKS 群集提供 Azure AD 身份验证。 OpenID Connect 是构建在 OAuth 2.0 协议顶层的标识层。 有关 OpenID Connect 的详细信息,请参阅 Open ID Connect 文档。
在 Azure AD 文档中详细了解 Azure AD 集成流程。
限制
- 无法禁用 AKS 托管的 Azure AD 集成。
- 不支持将 AKS 托管的 Azure AD 集成式群集更改为旧版 Azure AD。
- AKS 托管的 Azure AD 集成不支持未启用 Kubernetes RBAC 的群集。
开始之前
- 确保已安装且已配置 Azure CLI 版本 2.29.0 或更高版本。 运行
az --version
即可查找版本。 如果需要进行安装或升级,请参阅安装 Azure CLI。 - 你需要最低版本为 1.18.1 或
kubelogin
的kubectl
。 Kubernetes 和kubectl
的次要版本之间的差异不应超过一个版本。 如果未使用正确的版本,你会遇到身份验证问题。 - 如果使用 helm,所需的最低版本为 helm 3.3。
- 此配置要求你为群集提供 Azure AD 组。 此组在群集上注册为管理员组,以授予管理员权限。 如果没有现有的 Azure AD 组,可以使用
az ad group create
命令创建一个。
在 AKS 群集上启用 AKS 托管的 Azure AD 集成
创建新群集
使用
az group create
命令创建 Azure 资源组。az group create --name myResourceGroup --location centralus
创建一个 AKS 群集,并使用
az aks create
命令为 Azure AD 组启用管理访问权限。az aks create -g myResourceGroup -n myManagedCluster --enable-aad --aad-admin-group-object-ids <id> [--aad-tenant-id <id>]
成功创建 AKS 托管的 Azure AD 群集后,响应正文中会包含以下部分:
"AADProfile": { "adminGroupObjectIds": [ "5d24****-****-****-****-****afa27aed" ], "clientAppId": null, "managed": true, "serverAppId": null, "serverAppSecret": null, "tenantId": "72f9****-****-****-****-****d011db47" }
使用现有群集
使用 az aks update
命令在现有已启用 Kubernetes RBAC 的群集上启用 AKS 托管的 Azure AD 集成。 确保将管理员组设置为在群集上保留访问权限。
az aks update -g MyResourceGroup -n myManagedCluster --enable-aad --aad-admin-group-object-ids <id-1>,<id-2> [--aad-tenant-id <id>]
成功激活 AKS 托管的 Azure AD 群集后,响应正文中会包含以下部分:
"AADProfile": {
"adminGroupObjectIds": [
"5d24****-****-****-****-****afa27aed"
],
"clientAppId": null,
"managed": true,
"serverAppId": null,
"serverAppSecret": null,
"tenantId": "72f9****-****-****-****-****d011db47"
}
将旧式 Azure AD 群集升级为 AKS 托管的 Azure AD 集成
如果群集使用旧式 Azure AD 集成,则可以使用 az aks update
命令升级到 AKS 托管的 Azure AD 集成,而不会遇到故障时间。
az aks update -g myResourceGroup -n myManagedCluster --enable-aad --aad-admin-group-object-ids <id> [--aad-tenant-id <id>]
成功迁移 AKS 托管的 Azure AD 群集后,响应正文中会包含以下部分:
"AADProfile": {
"adminGroupObjectIds": [
"5d24****-****-****-****-****afa27aed"
],
"clientAppId": null,
"managed": true,
"serverAppId": null,
"serverAppSecret": null,
"tenantId": "72f9****-****-****-****-****d011db47"
}
访问 AKS 托管的已启用 Azure AD 的群集
使用
az aks get-credentials
命令获取用户凭据以访问群集。az aks get-credentials --resource-group myResourceGroup --name myManagedCluster
按照说明进行登录。
使用
kubectl get nodes
命令查看群集中的节点。kubectl get nodes
通过 kubelogin 进行非交互式登录
有一些当前无法通过 kubectl
执行的非交互式方案,例如持续集成管道。 可以使用 kubelogin
通过非交互式服务主体凭据连接到群集。
使用 1.24 版以上的 Kubernetes 版本的 Azure AD 集成群集自动使用 kubelogin
格式。 从 Kubernetes 版本 1.24 开始,Azure AD 群集的 clusterUser 凭据默认格式为 exec
,这需要使用执行 PATH 中的 kubelogin
二进制文件。
在获取 clusterUser 凭据时,可使用
format
查询参数覆盖默认行为。 可以将该值设置为azure
以使用原始 kubeconfig 格式:az aks get-credentials --format azure
如果 Azure AD 集成群集使用了低于 1.24 的 Kubernetes 版本,则需要手动转换 kubeconfig 格式。
export KUBECONFIG=/path/to/kubeconfig kubelogin convert-kubeconfig
注意
如果收到“错误: Azure 身份验证插件已移除。”消息,需要运行 kubelogin convert-kubeconfig
命令来手动转换 kubeconfig 格式。
排查 AKS 托管的 Azure AD 访问权限问题
重要
本部分中介绍的步骤会绕过正常的 Azure AD 组身份验证。 请仅在紧急情况下使用它们。
如果因为无权访问具有群集访问权限的有效 Azure AD 组而被永久阻止,你仍可以获取管理员凭据以直接访问群集。 你需要具有访问 Azure Kubernetes 服务群集管理员内置角色的权限。
后续步骤
- 了解 Azure AD 与 Kubernetes RBAC 的集成。
- 详细了解 AKS 和 Kubernetes 标识概念。
- 使用 Azure 资源管理器 (ARM) 模板创建已启用 AKS 托管 Azure AD 的群集。