GKE/Kubernetes CI/CD Pipelines with Jenkins:部署阶段的 Gcloud 身份验



作为 Jenkins 管道的一部分,用于构建应用程序并将其部署到 Google 的 Kubernetes 服务 (GKE(,我创建了一个脚本来执行以下到 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 容器服务进行身份验证的正确方法吗?

提前非常感谢任何帮助! 特拉亚诺

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

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

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

下面是一个演示,介绍如何使用 GitOps 在 Kubernetes 上使用多个环境自动化 CI/CD,以便在环境和拉取请求上的预览环境之间进行提升 - 使用 Spring Boot 和 nodejs 应用程序(但我们支持多种语言 + 框架(。

相关内容

最新更新