jenkins - 将 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 上单独运行。请帮忙
解决方案
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 .
}
}
}
推荐阅读
- javascript - 复制到剪贴板并消失消息
- vim - 无法在 vim 内的终端中返回终端模式
- java - JFrame 和 MouseListener 没有正确执行点击的问题
- entity-framework-core - 重用 Where 条件
- android - 不允许到本地主机的 NativeScript Angular 明文 HTTP 流量
- swift - 为什么泛型参数上的 AnyObject 约束不允许将该泛型参数用作约束?
- gpu - GPU 执行“流”与 CPU
- javascript - 在 html 文件中显示 xml 数据的内容不起作用
- cron - 运行计划作业的最佳方法是什么
- ios - Swift 5.1 NSInternalInconsistencyException 错误