Deployment Using Kubernetes(K8S) & Jenkins

Shailja Tripathi
5 min readJul 25, 2020

--

Docker is a container service provider that means it helps us with building, distributing and running container. Some of the use case in which we face problem is

  1. Auto Scaling: What if the clients exponentially increase and we have to scale or increase the number of container where our application is running? Manually going and launching container is not a good practice even we can have one monitoring software to look for the traffic and accordingly scale out and scale in. This will again add pain to our head. So we need one unified tool to handle this.
  2. Load Balancing: Let’s say after scaling if our program is not so intelligent to distribute the traffic to other containers auto scaling is of no use then, hence we need a software which also look for load balancing.
  3. Service Discovery: Let’s say we scaled out some container for our new clients and we even have load balancing for some existing containers, now how will the load balance program will come to know the IP of the newly created container? In this dynamic world even our IP is not constant, so we even need a program to have capability for service discovery.
  4. Reverse Proxy: Let’s say we have auto scaled, we have balanced the load, we have service discovery but we cannot give too many IP address to client to connect to our application, no one does that, it’s a very bad practice. So, we need a program which takes all the IP of the containers and give us one unique IP.
  5. Fault Tolerance: Here fault tolerance means once the container with our application is launched, we don’t want our clients to face any down time. Hence we need any system which can have a fault tolerance capability. So, this program have to continuously monitor the container running and if it fails it should automatically launch the new container.

We need this many things in one single program or tool. This is called container management tools. We have so many of them in the market, some of them are

  1. Kubernetes: Developed by Google
  2. Docker Swarm: Developed by Docker, Inc

Description of the Task

a)Create a container image that’s has Jenkins installed using a docker file.

b) When we launch this image, it should automatically starts Jenkins service in the container.

c) Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins

d) Job1: Pull the Github repo automatically when some developers push the repo to Github.

e) Job2 :

  1. By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes ( eg. If code is of HTML, then Jenkins should start the container that has HTML already installed )
  2. Expose your pod so that testing team could perform the testing on the pod
  3. Make the data to remain persistent ( If server collects some data like logs, other user information )

f) Job3: Test your app if it is working or not.

Create a docker file.

FROM centos:latest

RUN yum install wget -y

RUN yum install git -y

RUN yum install sudo -y

RUN wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-

stable/jenkins.repo

RUN rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

RUN yum install java-11-openjdk.x86_64 -y

RUN yum install jenkins -y

RUN yum install net-tools -y

RUN yum install python36 -y

RUN yum install initscripts -y

RUN echo -e "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER jenkins

ENV USER jenkins

USER root

RUN sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl
-s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

RUN sudo chmod +x ./kubectl

RUN sudo mv ./kubectl /usr/local/bin/kubectl

RUN sudo mkdir /root/.kube

COPY ca.crt /root/.kube/

COPY client.crt /root/.kube/

COPY client.key /root/.kube/

COPY config /root/.kube/
CMD ["java" ,"-jar", "/usr/lib/jenkins/jenkins.war"]

Build image-

dockerbuild -t task3:v3 .

This is the cmd by wich we can launch our container that has inbuilt jenkins and kubernetes setup.

docker run -it -p 8087:8080 --name task3 task3:v1

now go to browser and type vmip along with dedicated port for jenkins.

Now install suggested plugins and also some plugins that are not by default suggested as we integrate Kubernetes with Jenkins so we have to install some Kubernetes plugin in the jenkins name of some plugins are Kubernetes CLI.After Installing this we can get our Jenkins setup ready for our task.

Job 1

In this, We will fetch data from Github.

This will create job1 successfully

Job2

It will launch a new container that has an inbuild interpreter of the particular language that we download from Github.

This will launch PVC Deploy service.

Job3

Job4

Build Pipeline

Thankyou for Reading!

Sign up to discover human stories that deepen your understanding of the world.

--

--

No responses yet

Write a response