Auto Rolling-update in K8s using Dynamic Jenkins Cluster.

Abhishek Sharma
4 min readJul 17, 2020

Preface

What is jenkins?

Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.

With Jenkins, organizations can accelerate the software development process through automation. Jenkins integrates development life-cycle processes of all kinds, including build, document, test, package, stage, deploy, static analysis, and much more.

What is jenkins slave?

A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves:

  • It hears requests from the Jenkins Master instance.
  • Slaves can run on a variety of operating systems.
  • The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master.
  • You can configure a project to always run on a particular Slave machine or a particular type of Slave machine, or simply let Jenkins pick the next available Slave.

Problem statement:

Create A dynamic Jenkins cluster and perform task-3 using the dynamic Jenkins cluster.

Task3 link — https://medium.com/@abhishek.sharma58585/integration-of-github-jenkins-over-kubernetes-task3-278db3fb68a

Steps to proceed as:

  1. Create container image that’s has Linux and other basic configuration required to run Slave for Jenkins. ( example here we require kubectl to be configured )
    2. When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.
    3. Create a job chain of job1 & job2 using build pipeline plugin in Jenkins
    4. Job1 : Pull the Github repo automatically when some developers push repo to Github and perform the following operations as:
    1. Create the new image dynamically for the application and copy the application code into that corresponding docker image
    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:
    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.
    2. If Application created first time, then Expose the application. Else don’t expose it.

Here we start..

First we have to configure the Windows slave node.

Docker file for creating the httpd image..

FROM centos:latest

RUN yum install net-tools httpd php -y

COPY * /var/www/html/

EXPOSE 80/tcp

CMD [“/usr/sbin/httpd”, “-DFOREGROUND”]

Now time for creating the jobs in jenkins…

JOB1: Here we will download our files from github and build docker image from dockerfile then upload that docker image on dockerhub.

JOB2: Here 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)

This is the pipeline view of this jobs.

Here my task is completed

Thank you for reading…..

--

--