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.
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:
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,
Confusion 1
If I am using Kubernetes cluster for deployment, can I directly add kubectl
deployment command in Jenkinsfile ? Or Do I need to create any shell script in my VM?
Confusion 2
I have the Kubernetes cluster with 4 Vms - AWS EC2 Ubuntu 16.04 LTS. Ie, 1 Master and 3 worker machine.
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?
How the shell script can make to available in entire Kubernetes cluster?
Yes, you can use shell scripts to call kubectl, from your Jenkinsfile, for example:
sh 'kubectl ...'
However, my advice would be to use a shell script and put your commands inside that.
For an example, see: https://wade.be/development/2018/04/30/jenkinsfiles.html
Your shell script doesn't need to be in a VM at all, it just needs to be accessible by the Jenkins server.
Put it inside the code repository alongside where you store your Jenkinsfile.