【问题标题】:GKE/Kubernetes CI/CD Pipelines With Jenkins: Gcloud Authentication Issue in Deploy stage使用 Jenkins 的 GKE/Kubernetes CI/CD 管道:部署阶段的 Gcloud 身份验证问题
【发布时间】: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 运行的完整错误转储如下:

https://pastebin.com/pSWPQ5Ei

我的问题:

a) 如何解决这个问题?从 Jenkins 运行身份验证肯定不会那么难吗?

b) 这是从根本不在 Gcloud 基础架构上的 Jenkins 系统向 gcloud 容器服务进行身份验证的正确方法吗?

非常感谢您的帮助! 特拉亚诺

【问题讨论】:

  • 从错误转储中,我没有看到 gcloud auth activate-service-account --key-file ~/cicd_keyfile.json 被执行。你是否修改了它或者它以某种方式错过了执行?此行对于身份验证至关重要。

标签: jenkins kubernetes gcloud


【解决方案1】:

我们正在开发一个名为 Jenkins X 的开源项目,这是 Jenkins 基金会提出的一个子项目,旨在使用 Jenkins 和 GitOps 在 Kubernetes 上自动化 CI/CD 以进行推广。

我们通过在 kubernetes 集群内运行 Jenkins 管道解决了您遇到的一些问题;因此无需向 GKE 进行身份验证。

当您将更改合并到 master 分支时,Jenkins X 会为您的应用创建一个新的语义版本化发行版(pom.xml、jar、docker image、helm chart)。然后,管道会自动生成拉取请求,以通过 GitOps 在所有环境中推广您的应用程序。

这里是 a demo of how to automate CI/CD with multiple environments on Kubernetes using GitOps,用于在 Pull Requests 上的环境和预览环境之间进行推广 - 使用 Spring Boot 和 nodejs 应用程序(但我们支持多种语言 + 框架)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 2020-12-13
    • 1970-01-01
    • 2020-01-10
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多