Task 4 -Dynamic Jenkins Cluster And Deploying Application Using Kubernetes Minikube.

Jainrishabh
4 min readAug 19, 2020

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

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 are going to set up for Distributed job Cluster So there are some pre-requisite for this .

  1. Start Minikube : To use kubernetes service , we have to start minikube .

2 2. Tcp Socket Support : If docker client and server are using different systems then we have to enable Tcp Socket Support .

Go to this file >> /usr/lib/systemd/system/docker.service and add it

3 use these commands :

systemctl daemon-reload
systemctl restart docker

4

5 Create a docker file

Run docker file

docker tag kubernetes:v1 jainrishabh155/kubernetes:v1
docker push jainrishabh155/kubernetes:v1

Now to Configure Cloud , we have to install a plugin named “Docker” .

Then go to >>Manage Jenkins >> Manage Nodes and Clouds >>Configure Clouds .

Docker Host Url : tcp://<ip_of_docker_server>:4243

Remote File System Root : <jenkins_working_Directory>

Now it is done . The set up is ready .

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) .

It will download the code from github and copy in “/root/Task4_web” folder . This Code contains Dockerfile and webpages .

It will build and tag that image . After that push it to dockerhub .

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.

After setting up github use build in this .

now use My deployment.yml file

apiVersion: v1
kind: Service
metadata:
name: myweb
labels:
app: myweb
spec:
ports:
- port: 80
nodePort: 30105
selector:
app: myweb
tier: frontend
type: NodePort---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myweb
spec:
replicas: 1
selector:
matchLabels:
app: myweb
tier: frontendtemplate:
metadata:
name: myweb
labels:
app: myweb
tier: frontendspec:
containers:
- name: myweb
image: jainrishabh155/rish:latest

THANKS FOR READING.. This project is made by priyanshu goyal and RiSHABH jain..

--

--