【发布时间】:2017-07-11 17:19:21
【问题描述】:
作为构建应用程序并将其部署到 Google Kubernetes 服务 (GKE) 的 Jenkins 管道的一部分,我创建了一个脚本来执行以下对 GKE 的部署:
- 结帐码
- 为 gcloud 设置身份验证和
- 使用 kubectl 创建部署和服务:
脚本实现的详细步骤如下:
a) Create the docker registry authentication file (.json)
b) login to the google docker registry using the authentication file
c) initialise a git repo in the current directory
d) add the remote origin in prep for code pull
e) pull the source code for the microservice container
f) Create a kubectl configurtion file and directory to authenticate to the kubernetes cluster in Gcloud
g) Create a keyfile for a Gcloud service account that needs to authenticate to the container service
h) Activate the service account
i) Get the credentials for the container cluster from Gcloud
j) Run kubectl apply to create the kubernetes services
完整、经过测试的脚本位于:https://pastebin.com/sZPrQuzD
如果我将这一系列步骤放在 AWS EC2 实例上的脚本中并手动运行它,它就可以工作。但是,Jenkins 构建步骤在调用 kubectl 运行服务时失败,并出现以下错误:
gcloud container clusters get-credentials jenkins-cd --zone europe-west1-b --project noon-prod
Fetching cluster endpoint and auth data.
ERROR: (gcloud.container.clusters.get-credentials) ResponseError: code=403, message=Request had insufficient authentication scopes.
Build step 'Execute shell' marked build as failure
Jenkins 运行的完整错误转储如下:
我的问题:
a) 如何解决这个问题?从 Jenkins 运行身份验证肯定不会那么难吗?
b) 这是从根本不在 Gcloud 基础架构上的 Jenkins 系统向 gcloud 容器服务进行身份验证的正确方法吗?
非常感谢您的帮助! 特拉亚诺
【问题讨论】:
-
从错误转储中,我没有看到
gcloud auth activate-service-account --key-file ~/cicd_keyfile.json被执行。你是否修改了它或者它以某种方式错过了执行?此行对于身份验证至关重要。
标签: jenkins kubernetes gcloud