<p>I am trying to deploy docker image to kubernetes but hitting a strange issue. Below is the command i am using in jenkinsfile</p>
<pre><code>stage('Deploy to k8s') {
   steps{
       sshagent(['kops-machine']) {
         sh &quot;scp -o StrictHostKeyChecking=no deployment.yml ubuntu@&lt;ip&gt;:/home/ubuntu/&quot;
         sh &quot;ssh ubuntu@&lt;ip&gt; kubectl apply -f .&quot;
         sh 'kubectl set image deployment/nginx-deployment nginx=account/repo:${BUILD_NUMBER}'

    }
  }
</code></pre>
<p>I am getting this error message</p>
<ul>
<li>kubectl set image deployment/nginx-deployment nginx=account/repo:69
error: the server doesn't have a resource type &quot;deployment&quot;</li>
</ul>
<p>Strange thing is if i copy and paste this command and execute on the cluster, the image gets updated
<strong>kubectl set image deployment/nginx-deployment nginx=account/repo:69</strong>
Can somebody please help, image builds and pushes to docker hub successfully, its just that i am stuck with pulling and deploying to kubernetes cluster, if you have anyother alternatives please let me know, the deployment.yml file which gets copied to the server is as follows</p>
<pre><code>spec:
  containers:
  - name: nginx
    image: account/repo:3        
    ports:
    - containerPort: 80
</code></pre>

user3770612
<p>Ok so if found the work around. if i change this line in my docker file</p>
<pre><code>        sh &quot;ssh ubuntu@&lt;ip&gt; kubectl apply -f .&quot; to
        sh &quot;ssh ubuntu@&lt;ip&gt; kubectl set image deployment/nginx-deployment 
        nginx=account/repo:${BUILD_NUMBER}&quot;
</code></pre>
<p>It works, but if there is no deployment created at all, then i have to add these two line to make it work</p>
<pre><code>             sh &quot;ssh ubuntu@&lt;ip&gt; kubectl apply -f .&quot;
             sh &quot;ssh ubuntu@&lt;ip&gt; kubectl set image deployment/nginx-deployment 
             nginx=account/repo:${BUILD_NUMBER}&quot; 
</code></pre>
