CI-CD Pipeline on Kubernetes using Jenkins

CI-CD Pipeline on Kubernetes using Jenkins

Hello Everyone,

Today i am performing my previous task, on top of Kubernetes, where we use Kubernetes resources like Pods, ReplicaSet, Deployment, PVC and Service.

This task is the Upgradation task of below task, which was performed on top of DOCKER. You can check it also :)

Prerequisite for Performing this Task:

  • Rhel 7/8 vm
  • Docker
  • Minikube
  • kubectl configuration to work with kubernetes

Let's Begin, step by step :

1. Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7

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

Here i have created our Docker image using below Dockerfile :

No alt text provided for this image
# creating image jenkins-k8s:v3
FROM centos:latest
RUN yum install sudo -y
RUN sudo yum install wget -y

# installing git
RUN yum install git -y 

# configuraing jenkins repo
RUN sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

# installing java 
RUN yum install java-11-openjdk.x86_64 -y
RUN yum install initscripts.x86_64 -y

# installing jenkins 
RUN yum install jenkins -y 

# giving jenkins to root power
RUN echo -e "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# starting jenkins
CMD /etc/rc.d/init.d/jenkins start && /bin/bash

# installing kubectl 
RUN 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 chmod +x kubectl
RUN mv kubectl /usr/bin/

#  creating folder for copying 
RUN mkdir /root/.kube/
RUN mkdir /root/.minikube/


# copying k8s config file 
COPY config /root/.kube/

# copying all .minikube folder from host to container 
# this file contain "client.key" and "client.cert" file 
COPY .minikube /root/.minikube/

# copying ca.crt in /root/.minikube folder
COPY ca.crt /root/.minikube/

NOTE:

  1. First copy all the certificates of minikube inside the directory where your Dockerfile is present.
  2. You get this file from where you installed your minikube

After Run this Command for Image creation for jenkins :

docker build -t <image_name>:<image_version> <file_location_of_Dockerfile>
example: docker build -t jenkins-k8s:v3 /ws/

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

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

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

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 PHP, then Jenkins should start the container that has PHP already installed )

  2. Expose your pod so that testing team could perform the testing on the pod

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

Job4 : if app is not working , then send email to developer with error messages and redeploy the application after code is being edited by the developer

No alt text provided for this image
No alt text provided for this image

View of our complete task in one single go :)

No alt text provided for this image

Pod is created accordingly our code :

No alt text provided for this image

Thanks for Reading :)

Vikas Kumar

Software Engineer @evalueserve | Full Stack developer (MERN) | Node.js | Python | JavaScript | DB | Docker

4 年

Great work

Sanju Pal

Software Engineer 2 @ Progress | Golang & Kubernetes Specialist | Building Cloud-Native Solutions

4 年

Great????

要查看或添加评论,请登录

Sourabh Choudhary的更多文章

社区洞察

其他会员也浏览了