【发布时间】:2019-05-28 23:07:24
【问题描述】:
我们已将 Azure Kubernetes 集群配置为使用 Azure Active Directory RBAC。这意味着在使用 kubectl 时,我们首先需要以 AD 用户身份进行身份验证(通常通过 Web 浏览器手动完成设备代码身份验证来完成)。我们几乎完全按照 MSDN 文章 Integrate Azure Active Directory with Azure Kubernetes Service 进行了配置。
问题是 Azure DevOp Pipelines 中的 Kubernetes 构建/发布任务现在也需要此身份验证,例如当我们运行 kubectl apply 时:
2019-01-02T08:48:21.2070286Z ##[section]Starting: kubectl apply
2019-01-02T08:48:21.2074936Z ==============================================================================
2019-01-02T08:48:21.2075160Z Task : Deploy to Kubernetes
2019-01-02T08:48:21.2075398Z Description : Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.
2019-01-02T08:48:21.2075625Z Version : 1.1.17
2019-01-02T08:48:21.2075792Z Author : Microsoft Corporation
2019-01-02T08:48:21.2076009Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=851275)
2019-01-02T08:48:21.2076245Z ==============================================================================
2019-01-02T08:48:25.7971481Z Found tool in cache: kubectl 1.7.0 x64
2019-01-02T08:48:25.7980222Z Prepending PATH environment variable with directory: C:\agents\HephaestusForge\_work\_tool\kubectl\1.7.0\x64
2019-01-02T08:48:25.8666111Z [command]C:\agents\HephaestusForge\_work\_tool\kubectl\1.7.0\x64\kubectl.exe apply -f C:\agents\HephaestusForge\_work\r8\a\_MyProject\kubernetes\deploy.yaml -o json
2019-01-02T08:48:26.3518703Z To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code CUYYYYYVV to authenticate.
对此有什么解决方法?是否可以让 Azure DevOps 作为服务器客户端而不是 AD 客户端进行身份验证?
【问题讨论】:
-
我认为令牌是缓存的,可以一直使用到过期。登录或执行命令时是否还有其他错误?
-
@CharlesXu 如果我手动使用代码进行身份验证,那么它工作得很好。没有我可以使用的令牌。
-
我测试的时候,每次拿到凭证时只需要登录即可。然后凭证存储在文件 ~/.kube/config 中。也许您可以从代码中的文件中获取凭据。您也可以在代码中获取凭据时将其设置为变量。
-
可以使用github.com/Azure/kubelogin插件进行非交互登录
标签: azure azure-devops azure-active-directory azure-pipelines azure-aks