CI-CD Pipeline on Kubernetes using Jenkins
Sourabh Choudhary
Software Engineer | Java | Spring Boot | RestFul WebServices | Microservices | DSA
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 :
# 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:
- First copy all the certificates of minikube inside the directory where your Dockerfile is present.
- 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.
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
Job3 : Test your app if it is working or not.
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
View of our complete task in one single go :)
Pod is created accordingly our code :
Thanks for Reading :)
Software Engineer @evalueserve | Full Stack developer (MERN) | Node.js | Python | JavaScript | DB | Docker
4 年Great work
Software Engineer 2 @ Progress | Golang & Kubernetes Specialist | Building Cloud-Native Solutions
4 年Great????