gpt4 book ai didi

jenkins - 使用Jenkins的GKE/Kubernetes CI/CD管道:部署阶段的Gcloud身份验证问题

转载 作者:行者123 更新时间:2023-12-02 12:22:28 26 4
gpt4 key购买 nike

作为将应用程序构建和部署到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容器服务进行身份验证的正确方法吗?

    在此先感谢您的帮助!
    特拉亚诺

    最佳答案

    我们正在开发一个名为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应用程序(但我们支持许多语言和框架)。

    关于jenkins - 使用Jenkins的GKE/Kubernetes CI/CD管道:部署阶段的Gcloud身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45040933/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com