kubectl 与 GKE 集群的连接可通过虚拟机进行工作,但无法通过同一虚拟机的 Jenkins 管道进行连接
我有一个 Linux 虚拟机,可以毫无问题地运行 kubectl get pods 命令。
我发现,当我
gcloud container clusters get-credentials --cluster <cluster-name>
从该虚拟机运行:命令时,它会按预期将 kubeconfig 文件存储在 $HOME/.kube/config
中。
但是,当我在同一虚拟机中通过 jenkins 管道运行相同的步骤时,它会出现与 GKE 集群的连接超时问题。另外,kubeconfig 文件的内容相同,但这次的路径不同。它是在管道的当前目录中以 .kube 名称创建的。我也尝试过在管道中传递 --kubeconfig $HOME/.kube/config
但又出现了同样的问题。
I have a linux VM from where I am able to run kubectl get pods
command without any issue.
I have found out that when I run:
gcloud container clusters get-credentials --cluster <cluster-name>
command from this VM it stores the kubeconfig file in $HOME/.kube/config
as expected.
But when I am running same steps through a jenkins pipeline in same VM, its getting a connection timeout issue to GKE cluster. Also the kubeconfig file's content is same but its path is different this time. It's being created in the current directory of the pipeline under the name .kube simply. I have also tried passing --kubeconfig $HOME/.kube/config
in pipeline but its the same issue again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在 jenkins 管道中指定
$HOME
变量,您可以从jenkins 用户
的主目录请求 kube 配置文件,例如 /var/lib/jenkins。和:
,因此,解决方案是在 jenkins 作业中设置
KUBECONFIG
环境变量或设置--kubeconfig
标志并将它们指向现有的工作 kube 配置文件(检查 kube 配置路径)。查看所有可用的 jenkins 环境变量yourJenkinsUrl:port/env-vars.html
编辑:
有一个可能有用的解决方法 - 适用于 Jenkins 的 Kubernetes CLI 插件。
它是如何运作的?
By specifying
$HOME
variable in a jenkins pipeline you are requesting kube config file from the home dir of ajenkins user
, for example /var/lib/jenkins.And:
So, the solution is either setting the
KUBECONFIG
environment variable in a jenkins job or setting the--kubeconfig
flag and pointing them to the existing working kube config file (check the kube config path). See all available jenkins environment variables atyourJenkinsUrl:port/env-vars.html
EDIT:
There is a workaround that might be helpful - Kubernetes CLI plugin for Jenkins.
How it works?