<p>I am trying to implement CI/CD pipeline for my spring boot microservices. I am using Kubernetes and Jenkins for implementation of CI/CD pipeline. And also I am using SVN private code repository installed on on-premise server. And Kubernetes cluster forming using AWS EC2 Ubuntu 16.04 LTS AMI. </p>

<p>In my application I am planning to add Jenkinsfile and create shell script in VM for implementing the pipeline jobs. I am now exploring the following URLs for this:</p>

<ol>
<li><a href="https://www.brightbox.com/blog/2018/01/22/push-builds-to-dockerhub/" rel="nofollow noreferrer">https://www.brightbox.com/blog/2018/01/22/push-builds-to-dockerhub/</a></li>
<li><a href="http://www.tothenew.com/blog/automated-docker-deployment-using-jenkins/" rel="nofollow noreferrer">http://www.tothenew.com/blog/automated-docker-deployment-using-jenkins/</a></li>
<li><a href="https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html" rel="nofollow noreferrer">https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html</a></li>
</ol>

<p>Here I am seeing the script for pushing builded Docker image within Jenkinsfile. I understood the concept of Docker image pushing using configuration stage in Jenkinsfile. But here my doubt is that,</p>

<p><strong>Confusion 1</strong></p>

<p>If I am using Kubernetes cluster for deployment, can I directly add <code>kubectl</code> deployment command in Jenkinsfile ? Or Do I need to create any shell script in my VM?</p>

<p><strong>Confusion 2</strong></p>

<p>I have the Kubernetes cluster with 4 Vms - AWS EC2 Ubuntu 16.04 LTS. Ie,  1 Master and 3 worker machine.</p>

<p>So my another confusion is that, if I need to use one shell script in my Kubernetes cluster, in which Vm I need to write .sh file?  Do I need to write in  Master VM? Or need to add in worker Vm? Or need to add where I installed Jenkins master?</p>

<p>How the shell script can make to available in entire Kubernetes cluster? </p>

Mr.DevEng
<p>Yes, you can use shell scripts to call kubectl, from your Jenkinsfile, for example:</p>

<pre><code>sh 'kubectl ...'
</code></pre>

<p>However, my advice would be to use a shell script and put your commands inside that.</p>

<p>For an example, see: <a href="https://wade.be/development/2018/04/30/jenkinsfiles.html" rel="nofollow noreferrer">https://wade.be/development/2018/04/30/jenkinsfiles.html</a></p>

<p>Your shell script doesn't need to be in a VM at all, it just needs to be accessible by the Jenkins server. </p>

<p>Put it inside the code repository alongside where you store your Jenkinsfile.</p>
