小编Lio*_*che的帖子

从 jenkins 容器运行 kubectl 命令

我在 VirtualBox(ubuntu) 上安装了 minikube 来模拟部署环境并使用 Jenkins 管道。在我的 jenkins 容器上,我还安装了 kubectl 命令来控制 minikube。

所以我创建了以下阶段:

stage("k8s command test") {                        
        withCredentials([usernamePassword(credentialsId: 'cbcba826-ef01-4b18-856f-e6dc4eb27c1f', usernameVariable: 'my-user', passwordVariable: 'PASSWORD')]) {
            sh """
                kubectl config view
                kubectl create -f /home/my-user/file-svc.yml
            """
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的集群在输出中的第一件事似乎是空的:

+ kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []
Run Code Online (Sandbox Code Playgroud)

如果我检查 .kube/config 我有以下配置:

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/my-user/.minikube/ca.crt
    server: https://127.0.0.1:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-pipeline kubectl minikube

5
推荐指数
2
解决办法
7999
查看次数

标签 统计

jenkins ×1

jenkins-pipeline ×1

kubectl ×1

minikube ×1