GKE/Kubernetes CI/CD 使用 Jenkins 的管道:部署阶段的 Gcloud 身份验证问题
GKE/Kubernetes CI/CD Pipelines With Jenkins: Gcloud Authentication Issue in Deploy stage
作为构建应用程序并将其部署到 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 容器服务进行身份验证的正确方法吗?
非常感谢您的帮助!
特拉亚诺
我们正在开发一个名为 Jenkins X 的开源项目,该项目是 Jenkins 基金会提议的子项目,旨在使用 Jenkins 和 GitOps 在 Kubernetes 上实现 CI/CD 自动化以进行推广。
我们解决了您在 运行 kubernetes 集群中的 Jenkins 管道遇到的一些问题;因此无需使用 GKE 进行身份验证。
当您将更改合并到 master 分支时,Jenkins X 会为您的应用创建一个新的语义版本分布(pom.xml、jar、docker 图像、helm 图表)。然后,该管道会自动生成合并请求,以通过 GitOps 在所有环境中推广您的应用程序。
这里 a demo of how to automate CI/CD with multiple environments on Kubernetes using GitOps 用于在拉取请求上在环境和预览环境之间进行升级 - 使用 Spring Boot 和 nodejs 应用程序(但我们支持多种语言 + 框架)。
作为构建应用程序并将其部署到 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 容器服务进行身份验证的正确方法吗?
非常感谢您的帮助! 特拉亚诺
我们正在开发一个名为 Jenkins X 的开源项目,该项目是 Jenkins 基金会提议的子项目,旨在使用 Jenkins 和 GitOps 在 Kubernetes 上实现 CI/CD 自动化以进行推广。
我们解决了您在 运行 kubernetes 集群中的 Jenkins 管道遇到的一些问题;因此无需使用 GKE 进行身份验证。
当您将更改合并到 master 分支时,Jenkins X 会为您的应用创建一个新的语义版本分布(pom.xml、jar、docker 图像、helm 图表)。然后,该管道会自动生成合并请求,以通过 GitOps 在所有环境中推广您的应用程序。
这里 a demo of how to automate CI/CD with multiple environments on Kubernetes using GitOps 用于在拉取请求上在环境和预览环境之间进行升级 - 使用 Spring Boot 和 nodejs 应用程序(但我们支持多种语言 + 框架)。