Configuring CI/CD on Kubernetes with Jenkins

Configuring CI/CD on Kubernetes with Jenkins

So, this task is similar to my previous task on Jenkins but this time I have replaced docker with Kubernetes. So, I will try to write as short as possible.

Those who don’t know what Kubernetes is, in short it is a very intelligent tool for container orchestration.

You can study Kubernetes from official documentation.

And to study Docker in depth here is the playlist. – https://www.youtube.com/watch?v=3Kn6_b-1mK4&list=PLAi9X1uG6jZ30QGz7FZ55A27jPeY8EwkE

Here is the link to my last post in case you want to check it out – https://github.com/anantjakhmola/jenkins-project

Codes of Pods, Replica Set, Deployment, PVC and Service are present on : https://github.com/anantjakhmola/Devops-task3

OBJECTIVES 

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

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

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

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

5. Job2 :

·      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 ( e.g. If code is of PHP, then Jenkins should start the container that has PHP already installed )

·      Expose your pod so that testing team could perform the testing on the pod

·      Make the data to remain persistent ( If server collects some data like logs, other user information )

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

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

Kubernetes builds and deploy as well as update applications with no downtime. One of the most popular CI/CD tools now is Jenkins.

No alt text provided for this image

Here I am using jenkins installed on my rhel8

I think you have setup Kubernetes on your system also you can always follow the official guide to perform the installation of kubernetes.

Step 1: Login into Jenkins account

No alt text provided for this image

We need to configure the jobs so that whenever a developer pushes the code in github it automatically deploys it in kubernetes pods.

step 2 :creating first job that automatically pulls the code from github whenever developer pushes it .

No alt text provided for this image

Here the code is saved in a folder task3 .

Step 3:Now we have the developers code create a job which by looking at the code or program file, automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes.

No alt text provided for this image

Through this script in job if a developer pushes a html code then jenkins automatically starts a html pod and if the pod is not already present ,it creates a pod.

Here is the script for your reference

if sudo ls /task3 | grep html

then

 if sudo kubectl get pvc | grep html

 then

 echo "pvc for html already created"

 else

 sudo kubectl create -f /task3/html-pvc.yaml 

 fi

 if sudo kubectl get deploy | grep html-webserver

 then

   echo "already running"

 else

   sudo kubectl create -f /task3/html-deply.yaml 

 fi

else

echo "no html code from developer to host"

fi

 

htmlpod=$(sudo kubectl get pod -l app=html-webserver -o jsonpath="{.items[0].metadata.name}" )

sudo kubectl cp /task3/*.html  $htmlpod:/usr/local/apache2/htdocs

 

Step 4:Code is finally deployed ,now let’s perform some testing. for testing a jenkins job is created which test whether the code is properly deployed or not. If not, then a mail is sent to the developer to check for the code.

No alt text provided for this image

step 5: creating a job which sends the mail to developer if code is not working properly or a job fails.

Here I would like to thank my friend Vaishnavi Agarwal for this code snippet I don’t know why but my mail was not working at that time.

No alt text provided for this image

So, we have finally created a pipeline through jenkins that deploys the code in kubernetes whenever a developer pushes a code in github. This pipeline not only deploys but informs the developer if anything went wrong.

Let’s try to run it

No alt text provided for this image

we have pushed a code in github repo ,let’s see the deployment.

No alt text provided for this image

Our pipeline has started ,it has pulled the code from github repo and stored it.

No alt text provided for this image

Deployed the code and tested it ….

No alt text provided for this image

Finally, our pipeline is working.

Thinking of it Why not make it faster just from code. Watch the next article to find out how I am going to do it.

-------------------------------------

If you find the article useful do link it or if there are some suggestion do reply. Till then Keep learning.

Shivam Gupta

Java | Spring Boot | Microservices | Backend Developer | Researcher | Machine Learning | MLH Best Social Good Hack Winner

4 年

Good Work bro ??

回复

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

Anant Jakhmola的更多文章

  • Cloud Security the more the better

    Cloud Security the more the better

    Hey readers if you are reading this article I believe that you have already gone through the previous one if not here…

  • The Ultimate Security on Cloud

    The Ultimate Security on Cloud

    Hey Its me again and before you start wondering why this article let me tell you there is a saying that There are two…

  • Enhancing the Power of Server using Elastic File System

    Enhancing the Power of Server using Elastic File System

    Hey Again readers this is a upgraded version of my previous article on How terraform met Jenkins also there is a small…

  • A Small Music App Using Flutter

    A Small Music App Using Flutter

    Hey Readers so this week I tried my hands on with Flutter and tried creating a Music + Video App. Github Link:…

  • Wordpress on EKS

    Wordpress on EKS

    This will be a two part article In First Part I am Going to run and install wordpress on EKS and in second we will be…

  • Configuring CI/CD on Kubernetes with Jenkins and groovy

    Configuring CI/CD on Kubernetes with Jenkins and groovy

    So I told in my previous article that I will automate the stuff in that task and everything will be automatic so here…

  • Integrating Prometheus and Grafana with Kubernetes

    Integrating Prometheus and Grafana with Kubernetes

    Before Starting For those who are new to Prometheus and Grafana here is a short summary for that GRAFANA: Grafana is an…

  • Creating an End to End Application Pipeline with Dynamic Jenkins Slave

    Creating an End to End Application Pipeline with Dynamic Jenkins Slave

    So this is one of the interesting task in which we will be using Jenkins slaves on windows dynamic and use the…

  • DETECTING FACES USING TRANSFER LEARNING

    DETECTING FACES USING TRANSFER LEARNING

    Transfer learning (TL) is a research problem in machine learning (ML) that focuses on storing knowledge gained while…

  • Machine Learning Pipeline With Jenkins:MLOPS

    Machine Learning Pipeline With Jenkins:MLOPS

    Special Thanks to Shivam Gupta for this Diagram Check out his article if you want a different approach AutoML: Machine…

    4 条评论

社区洞察

其他会员也浏览了