Creating an End to End Application Pipeline with Dynamic Jenkins Slave
Girish Choudhary
Software Engineer @ Us2.ai | ICPC | Python | Django | JavaScript | node.js | React | AWS | GCP | Docker | K8s | DevOps | MLOps | ML/AI
>> Task:- Web Server with Live Updates Roll Out using Jenkins and Kubernetes
- Create a container image that has Linux and other basic configuration required to run Slave for Jenkins. ( example here we require kubectl to be configured ).
- When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.
- Create a job chain of job1 & job2 using build pipeline plugin in Jenkins.
- Job1 : Pull the Github repo automatically when some developers push repo to Github and perform the following operations as:
4.1 Create the new image dynamically for the application and copy the application code into that corresponding docker image.
4.2 Push that image to the docker hub (Public repository).
( Github code contain the application code and Dockerfile to create a new image )
5. Job2 ( Should be run on the dynamic slave of Jenkins configured with Kubernetes kubectl command): Launch the application on the top of Kubernetes cluster performing following operations:
5.1 If launching first time then create a deployment of the pod using the image created in the previous job. Else if deployment already exists then do rollout of the existing pod making zero downtime for the user.
5.2 If Application created first time, then Expose the application. Else don’t expose it.
i wont waste much time here in showing how to creating Jenkins image with dockerfile for this please refer to my previous articles
Lets start with the configuration of Windows slave node.
for this Manage Jenkins -> System Configuration -> Manage Nodes and Clouds -> New Node. Select Permanent Agent and give this node a name e.g. “Win Slave” as we will be using this for windows slave you can give any of your choice.
configuration of this slave node will be something like this
after successful configuration, we will be seeing this
Our node has been set up.
Time to create jobs
In job 1 we will download our files from github and build docker image from dockerfile then upload that docker image on dockerhub
used for connecting with GitHub
poll SCM will check GitHub every minute for updated
after -p you need to put your dockerhub password for login. with this script your image formation and upload both will be completed
In job 2 we will be doing connecting with windows slave and run kubectl commands there for this job we will be specifically using our slave node(I used k8s as a label for this node can be seen in above configuration image of the slave node)
for running commands, we will be using windows batch command shell instead of our regular one
This job will download the Kubernetes deployment code from github, check if the deployment does not already exist then it will create the deployment and expose it otherwise it will just roll-out the updates to the deployment.
our pipeline will look something like this
this whole setup will start when developer commit something in Github like this
my GitHub like for reference
Django Developer
4 年What does this do ?