<p>I am trying to deploy my Kubernetes Helm chart for sample Kubernetes cluster deployment. I created a sample Helm chart and added Docker image reference and deployed the Helm chart using terminal command <code>helm install &lt;my-chartname&gt;</code>. And micro service is accessing successfully without any problem.</p>

<p>After that I created a Jenkins pipeline job and added only one stage that containing the step for deployment. I added like the following way,</p>

<pre><code>pipeline 
{
    agent any
    stages 
        {
            stage ('helmchartinstall')
                {
                    steps
                    {
                        sh 'helm install spacestudychart'
                    }
                }
        }       
}
</code></pre>

<p>And I am getting the error like following ,</p>

<pre><code>[Pipeline] { (helmchartinstall)
[Pipeline] sh
+ helm install spacestudychart
Error: the server could not find the requested resource (get pods)
</code></pre>

<p>The same command is working when I am running through terminal. </p>

<p><strong>Update</strong></p>

<p>To upgrade tiller to latest version, I run the <code>helm init --upgrade</code> command on terminal. But the error remains still.</p>

<p><strong>Output of "helm version" is like the following,</strong></p>

<pre><code>Client: &amp;version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
Server: &amp;version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
</code></pre>

<p><strong>Output of "kubectl version --short" is like the following,</strong></p>

<pre><code>Client Version: v1.14.1
Server Version: v1.13.5
</code></pre>

<p>When I run command "kubectl --v=5 get pods; helm install spacestudychart" , I am getting the console output like the following,</p>

<pre><code>+ kubectl --v=5 get pods
I0604 07:44:46.035459    2620 cached_discovery.go:121] skipped caching discovery info due to yaml: line 10: mapping values are not allowed in this context
I0604 07:44:46.152770    2620 cached_discovery.go:121] skipped caching discovery info due to yaml: line 10: mapping values are not allowed in this context
I0604 07:44:46.152819    2620 shortcut.go:89] Error loading discovery information: yaml: line 10: mapping values are not allowed in this context
I0604 07:44:46.283598    2620 cached_discovery.go:121] skipped caching discovery info due to yaml: line 10: mapping values are not allowed in this context
I0604 07:44:46.374088    2620 cached_discovery.go:121] skipped caching discovery info due to yaml: line 10: mapping values are not allowed in this context
I0604 07:44:46.467938    2620 cached_discovery.go:121] skipped caching discovery info due to yaml: line 10: mapping values are not allowed in this context
F0604 07:44:46.468122    2620 helpers.go:114] error: yaml: line 10: mapping values are not allowed in this context
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE
</code></pre>

<p>Do I need to upgrade the kubectl version? What is the exact problem when running with Jenkins?</p>

<p>This is 100% working I have this problem before.</p>

<p>At first builts jenkins user next
copy <code>config</code> to <code>/home/jenkins/.kube/</code></p>

<pre><code>cp $HOME/.kube/config /home/jenkins/.kube/ 
or 
cp ~/.kube/config /home/jenkins/.kube/ 
</code></pre>

<p>And after that use</p>

<pre><code> chmod 777 /home/jenkins/.kube/config 
</code></pre>

<p>your kubernetes command need your kubernetes config file . it is like key or password for your kubernetes cluster so you should give the kubernetes config to your jenkins and after that it can run kubernetes commands</p>

<p>This is very good tutorial that help me to solve it .</p>

<p><a href="https://www.youtube.com/watch?v=288rTpd1SDE" rel="noreferrer">tutorial</a></p>

<p><strong>UPDATE1</strong>
you should have jenkins user for adding jenkins user you should add jenkins user to your ubuntu or centos or .. </p>

<pre><code>adduser jenkins
</code></pre>

<p>This is good link to adduser
<a href="https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart" rel="noreferrer">Adding user</a></p>

<p><strong>UPDATE 2</strong>
You should install kubectl in your server that you use it as <code>jenkins</code> so that kubectl command can work and after that please copy the config in <code>~/.kube/config</code> in your <code>kubernetes</code> cluster to your <code>jenkins</code> server that previously you installed <code>kubectl</code> on it.</p>
