首页 > 解决方案 > 将 Kubernetes 与 Jenkins 管道连接起来

问题描述

我正在尝试使用 Jenkins 管道中的 helm 部署容器。我已经为 jenkins 安装了 Kubernetes 插件,并为其提供了本地运行的 kubernetes URL 和凭据中的配置文件。当我在做的时候'Test connection',它正在显示'Connected to Kubernetes 1.16+'

但是当我从管道运行 helm install 命令时,它会给出错误

Error: Kubernetes cluster unreachable: the server could not find the requested resource

注意:我可以使用 CLI 和 Jenkins 管道执行所有操作,方法是使用withCredentials和传递 cred 文件变量名(在 jenkins 凭据中创建)。我只想做到这一点而不把它包裹在里面'withCredentials'

Jenkins 和 kubernetes 都在 Windows 10 上单独运行。请帮忙

标签: jenkinskuberneteskubernetes-helmmultibranch-pipeline

解决方案


Helm 使用 kubectl 配置文件。我正在使用这样的步骤。

steps {
        container('helm') {
          withCredentials([file(credentialsId: 'project-credentials', variable: 'PULL_KEYFILE')]) {
            sh """
            gcloud auth activate-service-account --key-file=${PULL_KEYFILE} --project project-name
            gcloud container clusters get-credentials cluster-name --zone us-east1
            kubectl create namespace ${NAMESPACE} --dry-run -o yaml | kubectl apply -f -
            """
            helm upgrade --install release-name .
          }
        }
      }

推荐阅读