?? DevOps Task-3??

?? DevOps Task-3??

Integrate Jenkins with Kubernetes

This will be a quick task NOT a detailed one we will just have to perform previous TASK i.e task2. In last task we used DOCKER in this we have to use Kubernates.

Link To Previous Task - 2 : https://www.dhirubhai.net/pulse/devops-task-2-tushar-dighe

Now we get to our this task....

Pre-requisites:

  1. Install minikube VM and Kubectl in the base OS (Windows) in order to use the Kubernetes Cluster

Objective :

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.

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

?Solution :

We are gonna use our Jenkins on RHEL8 for this job to work we need some configuration of Kubernates we need the kubectl command to be configured in the configuration of kubectl command.

  1. Start minikube server from the Windows Command Prompt.
minikube start

Copy these three files from windows to workstation for configuration.

C:\Users\Admin\.minikube\ca.crt

C:\Users\Admin\.minikube\profiles\minikube\client.crt

C:\Users\Admin\.minikube\profiles\minikube\client.key

Now we need a config file that will be used by kubectl to connect to our K8S cluster we will make a folder from name ".kube" and we will paste this file in that folder.

No alt text provided for this image

Create a Jenkins image with kubectl installed on it.

No alt text provided for this image

Build Command :

docker build -t tushardighe/jenkube:v1 .

No alt text provided for this image

Now our kubectl command is configured and we can use it in RHEL8 to access our cluster.

After successfully created this image push it on Docker hub. But the first login through command line in docker hub

docker login
docker push tushardighe/jenkube:v1

So your docker image is upload the dockerhub.com so you can use this image anywhere...using docker

Then you to use of the kubernetes so the create the PVC, Deployements and services of the kubernetes so write the .yml code to create this resources.

PVC (Persistent Volume Claim)

Create a YML file and write that code

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-data
  labels:
    app: jenkins
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

After that run

kubectl create -f file_name.yml

So it creates a PVC. After creating that you need to mount that PVC and also download that image. Better management, we create a Deployment.

apiVersion: apps/v1 
kind: Deployment
metadata:
  name: myweb
  labels:
    app: jenkins


spec:
  selector:
    matchLabels:
      app: jenkins
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: frontend
    spec:    
      containers:
      - image: tushardighe/jenkube:v1
        name: jenkins
        volumeMounts:
        - name: jenkins-persistent-storage
          mountPath: /root/.jenkins
      volumes:
      - name: jenkins-persistent-storage
        persistentVolumeClaim:
          claimName: jenkins-data

After that, we need to expose the Jenkins port 8080. For that

kubectl expose deployment myweb --type=NodePort --port=8080

Finally, you get Jenkins services start. If you want to see all things

kubectl get all

you get output look like this

No alt text provided for this image

After getting minikube IP and use that port 32122. You see your Jenkins service starts at that port in minikube IP. After setup Jenkins and download important plugins like Git, Github then start the things.

Now our task begins as we have done the similar task in task2 so we will not discuss it so deeply. So now we will just start jenkins and start building jobs.

Job1 will have simplest work to get code from the git hub it will download the code and store in a folder.

No alt text provided for this image

Now job2 we will launch pods we will launch them and we have to launch pod in respective pod so that they have perfect interpreter.

No alt text provided for this image

That's all we can deploy our code like this in this the reader.py file will give output as html then we deploy a pod from httpd image and if the reader.py gives php then we will use a image which has php installed.I have created 3 replicas you can create according to your requirement.

Job3 will have a remote which will be given to QAT team so they can test our code and redeploy of there is any problem i have written some simple code just to make sure pod is running.

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

we can write one more if statement there for php-pod but in my case i had html code so i have written that only.

Thanks for reading............


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

Tushar Dighe的更多文章

  • Enhancing Cloud Security with Wiz: A Game-Changer for DevOps and Security Teams

    Enhancing Cloud Security with Wiz: A Game-Changer for DevOps and Security Teams

    Enhancing Cloud Security with Wiz: A Game-Changer for DevOps and Security Teams In today's fast-paced cloud…

  • AWS : NASA Case Study

    AWS : NASA Case Study

    Established in 1958, the National Aeronautics and Space Administration (NASA) has been working around the world—and off…

  • The World of “Big Data”

    The World of “Big Data”

    What is data? The quantities, characters, or symbols on which operations are performed by a computer, which may be…

  • ?? Hybrid Multi Cloud Task-3??

    ?? Hybrid Multi Cloud Task-3??

    INTEGRATION OF WORDPRESS RUNNING ON TOP OF KUBERNETES CLUSTER WITH AWS RDS.?? So, you might be thinking that what is…

    2 条评论
  • ?? Hybrid Multi Cloud Task-2??

    ?? Hybrid Multi Cloud Task-2??

    Using EFS service with Terraform. Objective: Perform the task-1 using EFS instead of EBS service on the AWS as…

  • ?? Hybrid Multi Cloud Task-1??

    ?? Hybrid Multi Cloud Task-1??

    To launch Webserver with AWS using Terraform code Steps required to launch the App using terraform:- 1. Create the key…

  • ?? Ansible Task-2??

    ?? Ansible Task-2??

    Deploying Web Server on AWS through ANSIBLE! TASK DESCRIPTION: ?? Provision EC2 instance through ansible. ?? Retrieve…

  • ?? DevOps Task-6 ??

    ?? DevOps Task-6 ??

    Integration of Jenkins with Kubernetes using groovy What is Groovy? Groovy is a Java-syntax-compatible object-oriented…

  • ?? DevOps Task-5 ??

    ?? DevOps Task-5 ??

    Deploy prometheus and grafana on the top of kubernetes . Tasks : Integrate Prometheus and Grafana and perform in…

  • ?? DevOps Task-4 ??

    ?? DevOps Task-4 ??

    In this article i have created a fully automated CI/CD build pipeline by using the technology git, github, Jenkins…

社区洞察

其他会员也浏览了