Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60798

Setup Kubernetes CLI (kubectl) error: "FATAL: Failed to run kubectl version 1"

    • kubernetes 1.23.3

      In latest release (1.23.0) I'm getting the below error while trying to use the "Setup Kubernetes CLI (kubectl)" in a job where field "Certificate of authority" is empty and field "Credentials" is populated from type "Username and password":

      [...]
      Building in workspace /var/jenkins_home/workspace/backups
      $ kubectl version
      FATAL: Failed to run kubectl version 1
      java.io.IOException: Failed to run kubectl version 1
      at org.csanchez.jenkins.plugins.kubernetes.KubectlBuildWrapper.setUp(KubectlBuildWrapper.java:94)
      at jenkins.tasks.SimpleBuildWrapper.setUp(SimpleBuildWrapper.java:146)
      at hudson.model.Build$BuildExecution.doRun(Build.java:157)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
      at hudson.model.Run.execute(Run.java:1853)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:427)
      Finished: FAILURE

      The previous version (1.22.5) works fine and after downgrading all jobs started to work again.
      This happened in two independent Jenkins boxes running the latest LTS Jenkins ver. 2.204.1.

       

      After further investigation, the issue seems to be related to kubernetes config file setup. Although I didn't specify a certificate, the property insecure-skip-tls-verify is set to false, plus the current-context is not set. Sample generated file below: 

      $ cat .kube2280516965942825275config
      ---
      clusters:
      - cluster:
       insecure-skip-tls-verify: false
       server: "https://api.k8s-cluster.dummy.com"
       name: "k8s"
      contexts:
      - context:
       cluster: "k8s"
       user: "cluster-admin"
       name: "k8s"
      users:
      - name: "cluster-admin"
       user:
       as-user-extra: {}
       password: "XXXXXXXXXXXXX"
       username: "jenkins"

       

          [JENKINS-60798] Setup Kubernetes CLI (kubectl) error: "FATAL: Failed to run kubectl version 1"

          Just tested this with version 1.23.2 and issue is still happening.

          The only difference is the error message in the jenkins job (the generated config file has the same issues).
          [...]
          Building in workspace /var/jenkins_home/workspace/backups
          $ kubectl version
          ERROR: Failed to run kubectl version. Returned status code 1.
          Finished: FAILURE

          João Salavessa added a comment - Just tested this with version 1.23.2 and issue is still happening. The only difference is the error message in the jenkins job (the generated config file has the same issues). [...] Building in workspace /var/jenkins_home/workspace/backups $ kubectl version ERROR: Failed to run kubectl version. Returned status code 1. Finished: FAILURE

          I probably read the initial report too quickly. The problem seems to be no current context is set.

          Vincent Latombe added a comment - I probably read the initial report too quickly. The problem seems to be no current context is set.

          Vincent Latombe added a comment - salavessa could you try with https://repo.jenkins-ci.org/incrementals/org/jenkinsci/plugins/kubernetes-credentials/0.6.1-rc83.76c66431124a/ ?

          Tested: job fails with the same message.

          The "current-context" is now set correctly but the cluster's "insecure-skip-tls-verify" is not present (and I suppose kubectl defaults that to false).

          Generated file below:

          $ cat .kube4111259011631954122config
          ---
          clusters:
          - cluster:
          {{ server: "https://api.internal.k8s.com"}}
          {{ name: "k8s"}}
          contexts:
          - context:
          {{ cluster: "k8s"}}
          {{ user: "cluster-admin"}}
          {{ name: "k8s"}}
          current-context: "k8s"
          users:
          - name: "cluster-admin"
          {{ user:}}
          {{ as-user-extra: {}}}
          {{ password: "......"}}
          {{ username: "jenkins"}}

          João Salavessa added a comment - Tested: job fails with the same message. The " current-context " is now set correctly but the cluster's " insecure-skip-tls-verify " is not present (and I suppose kubectl defaults that to false ). Generated file below: $ cat .kube4111259011631954122config --- clusters: - cluster: {{ server: "https://api.internal.k8s.com"}} {{ name: "k8s"}} contexts: - context: {{ cluster: "k8s"}} {{ user: "cluster-admin"}} {{ name: "k8s"}} current-context: "k8s" users: - name: "cluster-admin" {{ user:}} {{ as-user-extra: {}}} {{ password: "......"}} {{ username: "jenkins"}}

          João Salavessa added a comment - - edited

          Running kubectl with the above file I get the below:

          $ kubectl --kubeconfig=.kube4111259011631954122config version
          Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"clean", BuildDate:"2019-11-13T11:20:18Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
          Unable to connect to the server: x509: certificate signed by unknown authority

          If I add "insecure-skip-tls-verify: true" to the file it works as expected:

          $ kubectl --kubeconfig=.kube4111259011631954122config_insecure-skip-tls-verify-true version
          Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"clean", BuildDate:"2019-11-13T11:20:18Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
          Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"clean", BuildDate:"2019-11-13T11:11:50Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

          João Salavessa added a comment - - edited Running kubectl with the above file I get the below: $ kubectl --kubeconfig=.kube4111259011631954122config version Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"clean", BuildDate:"2019-11-13T11:20:18Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64" } Unable to connect to the server: x509: certificate signed by unknown authority If I add " insecure-skip-tls-verify: true " to the file it works as expected: $ kubectl --kubeconfig=.kube4111259011631954122config_insecure-skip-tls-verify-true version Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"clean", BuildDate:"2019-11-13T11:20:18Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64" } Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"clean", BuildDate:"2019-11-13T11:11:50Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64" }

          salavessa should be fixed in 1.23.3

          Vincent Latombe added a comment - salavessa should be fixed in 1.23.3

          vlatombe just to confirm that 1.23.3 seems to be working fine.

          Thanks!

          João Salavessa added a comment - vlatombe just to confirm that 1.23.3 seems to be working fine. Thanks!

            vlatombe Vincent Latombe
            salavessa João Salavessa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: