Creating jobs to configure ci/cd with kubernetes in Jenkins, which is started in a docker container and then using ssh to reach kubernetes on the base os.

We will first build a docker image using Dockerfile to run Jenkins. The Dockerfile can be made as follows:

FROM centos:7
RUN yum install wget -y
RUN yum install sudo -y
RUN yum install git -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 /sbin/service -y
RUN echo -e "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
CMD java -jar /usr/lib/jenkins/jenkins.war
EXPOSE 8080

Dockerfile is created using

docker build -t jenkins:v1

The image can also be pulled using docker pull ishajain140/jenkins:v1 .

Now we can start our container using the following command and after the container is built we are provided with Jenkins login username and password.

docker run -it --privileged -v /root/devops6/:/host -p 8081:8080 --name jenkinsos jenkins:v1

Image for post

Jenkins user name and password

Open the IP of your VM for Jenkins on port 8081 and enter the given username and password and install suggested plugins. An extra plugin is required to create a job in Jenkins DSL language. To install it:

Go to Manage Jenkins >> Manage Plugins >> Available >> search for job DSL plugin

Image for post

Jenkins login page; enter a password here

Image for post

select “install suggested plugins”

Image for post

#jenkins #groovy #kubernetes #ci-cd-pipeline #ssh

CI/CD on Jenkins with Kubernetes using Groovy Language
1.50 GEEK