DEVOPS TASK 3

DEVOPS TASK 3


FLOW CHART OF THE TASK GIVEN:

No alt text provided for this image

TASK DESCRIPTION:

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

No alt text provided for this image

Dockerfile For Jenkins

To build this image use the command as shown below :

In the Jenkins Dockerfile I have installed mailx for sending the mail and copied my custom python script for detecting the extension of the file and then on the basis of that, it builds the image and pushes to the docker hub.

    docker build -t <name/of/theimage>  <path/to/Dockerfile>



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

No alt text provided for this image

As you can see the Jenkins is running , and to access it from your docker host or outside you need to do PATing ie Port Address Translation.

   docker run -dit -p 8080:8080  --name jenkins  <jenkins/image/name>



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.

No alt text provided for this image



I have used git post-commit hook to automate the pull after commit done by the Developer.

No alt text provided for this image

The webhook will trigger the Jenkins job to build the image with the new code pushed by the Developer and for that i have used ngrok (for tunneling) so as to provide the (public)ip to which github can connect to.

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

The python script will build and push the image to the Docker Hub and BUILD_NUMBER will be used as the tag for the image.


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 )

I have created the html_deployment and php_deployment yaml file along with the pvc for the document root directory and the logs.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: php-pvc
  labels:
    env: test
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---


apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: php-log-pvc
  labels:
    env: test
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---


apiVersion: v1
kind: Service
metadata:
  name: php-svc
  labels:
    name: php-svc
spec:
  selector:
    name: php-pod
  ports:
  - port: 80
    targetPort: 80
    nodePort: 32000
  type: NodePort


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-app
  labels:
    name: php-app
    env: test
spec:
  replicas: 1
  selector:
    matchExpressions:
    - { key: name, operator: In , values: [ php-pod ] }
  template:
    metadata:
      name: php-pod
      labels:
        name: php-pod
    spec:
      containers:
      - name: php-con
        image: raghav1674/php-6:v1
        volumeMounts:
        - name: php-log
          mountPath: /var/log/httpd/
        - name: php-dir
          mountPath: /var/www/php/
      volumes:
      - name: php-log
        persistentVolumeClaim:
          claimName: php-log-pvc
      - name: php-dir
        persistentVolumeClaim:
          claimName: php-pvc





This is the php_site_deployment.yaml file

No alt text provided for this image

This job is for the HTML site which will be triggered by the previous job using the remote trigger.

No alt text provided for this image

This job is for the PHP site which will be triggered by the previous job using the remote trigger.

Job3 : Test your app if it is working or not.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
No alt text provided for this image


Lets see all these jobs in action:

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

Initially, no k8s resource is there.

No alt text provided for this image

After I pushed the image and the code file to the Github

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

Site is working fine.

No alt text provided for this image

Test success

Then I intentionally made some error in the PHP code to test my job is working properly or not.

No alt text provided for this image

Made Syntax Error in the PHP code.

No alt text provided for this image

The PHP site returns HTTP code 500 so the rollback is made and the developer is informed through mail.

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

Rollback done


Keep going Sir ji, You are a great learner and tutor too.... always thankful for ur support

To view or add a comment, sign in

More articles by Raghav Gupta

  • What actually Containers are?

    If you are familiar with containers, you might know Docker, What actually Docker is? Is it a Container Engine or a…

    2 Comments
  • Provisioning and Configuring Jenkins Dynamic Slaves on AWS EC2 Using Ansible

    Jenkins: Jenkins is a free and open-source automation server. It helps automate the parts of software development…

    2 Comments
  • Kubernetes Industry Use Case- OpenAI

    OpenAI is an artificial intelligence research laboratory consisting of the for-profit corporation OpenAI LP and its…

  • BOSCH And Azure AKS

    PROBLEM: THE WRONG WAY DRIVING PROBLEM The problem of drivers going the wrong way on highways, the goal was to save…

  • ARTH TASK 3

    TASK DESCRIPTION: 🔅 Create a key pair 🔅 Create a security group 🔅 Launch an instance using the above created key…

    2 Comments
  • Slack Case Study - AWS

    Slack provides a messaging platform that integrates with and unifies a wide range of communications services such as…

    2 Comments
  • INTRO TO BIG DATA AND DISTRIBUTED STORAGE CLUSTERS

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

    2 Comments
  • HYBRID MULTI CLOUD TASK 6

    TASK DESCRIPTION: Deploy the Wordpress application on Kubernetes and AWS using terraform including the following steps;…

  • HYBRID MULTI CLOUD TASK 2

    Task-Description: Create/launch Application using Terraform 1. Create a Security group that allows the port 80.

  • Ansible Task 3

    𝗧𝗮𝘀𝗸 3:- ♦️ Provision EC2 Instances Through Ansible. ♦️ Retrieve The IP Address of Instances Using The Dynamic…

    1 Comment

Others also viewed

Explore content categories