<p>I have deployed jenkins on the kubernetes cluster using helmchart by following this:</p>
<p><a href="https://octopus.com/blog/jenkins-helm-install-guide" rel="nofollow noreferrer">https://octopus.com/blog/jenkins-helm-install-guide</a></p>
<p>I have the pods and services running in the cluster. I was trying to create a pipeline to run some kubectl commands. It is failing with below error:</p>
<p>java.io.IOException: error=2, No such file or directory
Caused: java.io.IOException: Cannot run program &quot;kubectl&quot;: error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)</p>
<p>I thought that it has something to do with the Kubernetes CLI plugin for jenkins and raised an issue here:</p>
<p><a href="https://github.com/jenkinsci/kubernetes-cli-plugin/issues/108" rel="nofollow noreferrer">https://github.com/jenkinsci/kubernetes-cli-plugin/issues/108</a></p>
<p>I have been advised to install kubectl inside jenkins pod.</p>
<p>I have the jenkins pod already running (deployed using helmchart). I have been seeing options to include the kubectl image binary as part of the dockerfile. But, I have used the helmcharts and not sure if I have to luxury to edit and deploy the pod to add the kubectl.</p>
<p>Can you please help with your inputs to resolve this? IS there any steps/documentation that explain how to install kubectl on the running pod? Really appreciate your inputs as this issue stopped one of my critical projects. Thanks in advance.</p>
<p>I tried setting the rolebinding for the jenkins service account as mentioned here:</p>
<p><a href="https://stackoverflow.com/questions/67103431/kubernetes-commands-are-not-running-inside-the-jenkins-container">Kubernetes commands are not running inside the Jenkins container</a></p>
<p>I haven't installed kubectl inside pod yet. Please help.</p>
<p>Jenkins pipeline:</p>
<pre><code>kubeconfig(credentialsId: 'kube-config', serverUrl: '')
sh 'kubectl get all --all-namespaces'
</code></pre>
<p>(attached the pod/service details for jenkins)<a href="https://i.stack.imgur.com/HZSdp.png" rel="nofollow noreferrer">enter image description here</a></p>

Siva
<p>Despite  jenkins agent pod is runinng inside kubernetes cluster, jenkins agent container itself does not have <code>kubectl</code> utility installed.</p>
<p>You may have to build your own jenkins agent docker image, install all the tools you need and then use it instead of the default jenkins agent.</p>
<p>Dockerfile for your custom agent may contain lines like this:</p>
<pre><code>FROM jenkins/inbound-agent:4.11-1-jdk11

USER root

RUN apt-get update \
    &amp;&amp; apt-get install -y curl \
    &amp;&amp; curl -LO &quot;https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot; \
    &amp;&amp; chmod 755 kubectl \
    &amp;&amp; mv kubectl /bin

USER jenkins
</code></pre>
<p>and in your helm values.yaml instead of default</p>
<pre><code>agent:
  image: &quot;jenkins/inbound-agent&quot;
  tag: &quot;4.11.2-4&quot;
</code></pre>
<p>you may set</p>
<pre><code>agent:
  image: &quot;your-dockerhub-repo/custom-jenkins-agent&quot;
  tag: &quot;1.0.0-your-version&quot;
</code></pre>
