Integrating Jenkins with Kubernetes(DevOps Task-3)

Integrating Jenkins with Kubernetes(DevOps Task-3)

Alright, so let's first see the Problem Statement:

  1. Create container image that has Jenkins installed using Docker File or you can use the Jenkins Server RHEL 8/7.
  2. When we launch this image, it should automatically starts 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 : 

  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

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

Alright, so let's start with the fun part:

So, in the first part, I will be using a Dockerfile, and in order to create your own Dockerfile, head over to your RedHat and remember to save your file name as Dockerfile and file extension as all files, in this case, the file should look like this:

No alt text provided for this image

We will be exposing our port 8080, because Jenkins uses port 8080.

So before jumping into using Jenkins, let me show you how to use Jenkins on Windows when it is installed on RedHat 8 Virtual Machine. First of all you need to have Jenkins installed on RedHat 8(Obviously!)

So, run these below commands on your RedHat 8 terminal:

No alt text provided for this image

And then, to check the IP address of your Virtual Machine, run ifconfig command, and on the first in the section named enp0s3, copy the numbers after inet, yours will be different:

No alt text provided for this image

Now go to your preferred browser in Windows, I will be using Edge, and paste the numbers you have copied(That is your IP address), and;

No alt text provided for this image

Your Jenkins should have loaded:

No alt text provided for this image

Step 1: To build the Docker image, build it using docker build -t NAME:TAG /location of Dockerfile/

Run a container from your newly built image and expose it to any available port using PAT, for example docker run -it -p 2301:8080 --name jenpro jentest:v5

Step 2: Now, let's move on to the tasks on Jenkins:

For Step 2, in Task 1, the code will be auto downloaded from GitHub, and for the same I will be using trigger method, it might sound complicated, but let me take you through the process step by step and you will realize that it is damn simple.

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

I have provided the link along with the authentication token to my local git, as soon as code is pushed, Git hook would work and run this task automatically. In the execute shell section, the webpages are being downloaded to this folder inside the container.

No alt text provided for this image

Task 2: Transfer In this task, the web pages downloaded inside the container are being transferred to the base Redhat using scp. I have already authorized a ssh key from my container to Redhat.

No alt text provided for this image

Task 3: Deployment In this task, the file type is checked by checking the extension, for example if the pages are built in html, then the extension of the file will be .html(obviously!), so then the code would detect that it is a html file and so launch an httpd server to deploy the pages, and to understand it further, if the pages are built in php, then the extension will be .php, and so a php supporting container would be deployed.

In order to run kubectl through your RedHat, make sure you have minikube running, and all of the necessary keys and certificates are transferred to RedHat and the config file is successfully built. I am giving an example config file below:

apiVersion: v1
kind: Config

clusters:
- cluster:
    server: https://192.168.0.192:8443
    certificate-authority: /root/ca.crt
  name: my_cluster

contexts:
- context:
    cluster: my_cluster
    user: naitik

users:
- name: naitik
  user:
    client-key: /root/client.key
    client-certificate: /root/client.crt

Remember, that the above file is just an example, and your file will be different.

So, after creating the above file(config file), save it in .kube folder, and so now you can access the kubernetes via RedHat.

No alt text provided for this image

Task 4: So, this is the last task of this problem statement. This is the Testing task, and the deployed code will be tested, and in case it finds any error, an email to the desired email address will be sent, and for the same, I will be using status method, so in that method, whenever we access any web page using curl and Linux, the status 200 states that the page is working or it is not working. So, I will be using the same concept.

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

And done, your problem statement is done, and now, if your email service isn't working, make sure you have enabled less secure app access and turn off two step authentication.

After you have completed all of the above steps, run sudo service Jenkins restart in your Jenkins container.

So, now open your IP address in your web browser and see your website.

So, as we have used Kubernetes, if the pods crash, sit back and relax(because that is what DevOps is all about), the replica set working behind the deployment will relaunch the pods.

So, that's all from my side guys, see you later! and suggestions are welcome!

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

Naitik Shah的更多文章

  • JavaScript - Journey from Zero to Hero with Vimal Daga Sir

    JavaScript - Journey from Zero to Hero with Vimal Daga Sir

    I have seen a lot of "Free" courses on YouTube, which assure you to take your basic level in JavaScript to next level…

  • Hybrid Computing Task 1

    Hybrid Computing Task 1

    Why Cloud? Many companies have a hard time maintaining their data centers. It's also inconvenient for new startups to…

    2 条评论
  • Chest X-Ray Medical Diagnosis with Deep Learning

    Chest X-Ray Medical Diagnosis with Deep Learning

    Project Name: Chest X-Ray Medical Diagnosis with Deep Learning Team Members: Naitik Shah Ashutosh Kumar Sah This…

    2 条评论
  • Top 5 Billion Dollar Companies Using AWS Cloud

    Top 5 Billion Dollar Companies Using AWS Cloud

    Hello Readers, AWS has captured a whopping 51% of the total cloud computing service providers, and their competitors…

    2 条评论
  • Multi-Cloud Project

    Multi-Cloud Project

    A quick summary of the project: The purpose is to deploy a WordPress framework using Terraform on Kubernetes. For this,…

    2 条评论
  • Data Problem of Big Tech Companies

    Data Problem of Big Tech Companies

    Every hour, 30,000 hours of videos are uploaded to YouTube, crazy isn't it? and that data is of March 2019, so, I am…

    2 条评论
  • Hybrid Cloud Computing Task 4

    Hybrid Cloud Computing Task 4

    Hey fellas, presenting you my Hybrid Cloud Computing Task 4, which I am doing under the mentorship of Vimal Daga Sir…

  • Hybrid Cloud Computing Task 3

    Hybrid Cloud Computing Task 3

    Hey fellas, I bring you the Hybrid Cloud Computing task 3. What is this task all about? The motive is for our company…

  • Automating AWS Service(EC2, EFS, S3, Cloud Front) using Terraform

    Automating AWS Service(EC2, EFS, S3, Cloud Front) using Terraform

    So let me take you through the steps: First of all, create an IAM user by going to AWS GUI, and don't forget to…

  • Deploying Prometheus and Grafana on top of Kubernetes

    Deploying Prometheus and Grafana on top of Kubernetes

    Hello readers, this is my DevOps Task 5, and the problem statement is: Integrate Prometheus and Grafana and perform in…

社区洞察

其他会员也浏览了