<p>I have the following Jenkinsfile:</p>
<pre><code>node {
  stage('Apply Kubernetes files') {
    withKubeConfig([credentialsId: 'jenkins-deployer', serverUrl: 'https://192.168.64.2:8443']) {
      sh 'kubectl apply -f '
    }
  }
}
</code></pre>
<p>While running it, I got &quot;kubectl: not found&quot;. I installed Kubernetes-cli plugin to Jenkins, generated secret key via <code>kubectl create sa jenkins-deployer</code>. What's wrong here?</p>

Matty
<p>I know this is a fairly old question, but I decided to describe an easy workaround that might be helpful.<br />
To use the <a href="https://plugins.jenkins.io/kubernetes-cli/" rel="noreferrer">Kubernetes CLI</a> plugin we need to have an executor with <code>kubectl</code> installed.</p>
<p>One possible way to get <code>kubectl</code> is to install it in the Jenkins pipeline like in the snipped below:<br />
<strong>NOTE:</strong> I'm using <code>./kubectl get pods</code> to list all Pods in the default Namespace. Additionally, you may need to change <code>kubectl</code> version (<code>v1.20.5</code>).</p>
<pre><code>node {
  stage('List pods') {
    withKubeConfig([credentialsId: 'kubernetes-config']) {
        sh 'curl -LO &quot;https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl&quot;'  
        sh 'chmod u+x ./kubectl'  
        sh './kubectl get pods'
    }
  }
}
</code></pre>
<p>As a result, in the Console Output, we can see that it works as expected:</p>
<pre><code>curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl
  ...
[Pipeline] sh
+ chmod u+x ./kubectl
[Pipeline] sh
+ ./kubectl get pods
NAME            READY   STATUS    RESTARTS   AGE
default-zhxwb   1/1     Running   0          34s
my-jenkins-0    2/2     Running   0          134m
</code></pre>
