DevOps-Project-6

DevOps-Project-6

This article contain complete integration of git , github , jenkins , Kubernetes for deploying the web page using full automation with groovy code . I have launch complete environment for jenkins process using Dockerfile.

Task-6

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. Job2 ( Seed Job ) : Pull the Github repo automatically when some developers push repo to Github.

5. Further on jobs should be pipeline using written code using Groovy language by the developer

6. Job1 :  

  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 using PVC ( If server collects some data like logs, other user information )

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

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

Prerequisite for this project is

  • I have windows operating system in which i have already install git bash ,
  • kubernetes and kubectl have configured.
  • I have Redhat 8 operating system which is running on the top of windows by virtualization. in this, my Docker is running.
  • for Source Code Management i have github account and i have also account on hub.docker.com where i can push my images.
  • and i have stop the firewall using systemctl stop firewalld and selinux using setenforce 0 so that there will no issue in connectivity between two VM.

__________________________________________________________________________

Start Building

First we have to create Jenkins Docker image in which we have to configure kubectl too.

  • In the below screenshot I have created a Dockerfile in which i have install all the the software that will use in my project.
No alt text provided for this image
  • I am copying some file like client.key , ca.crt , client.crt these are the key and certificate for configure the kubectl in another vm. because my kubernetes and kubectl is install in my windows operating system. now i am configuring kubectl in another vm that's why i need these files.
  • i am copying another file which is myinfo
No alt text provided for this image
  • this is file is for configure the kubectl command. it include all the information which is required the kubeclt to run in another vm like: ip and port number of minikube and location of keys and certificates.

Build this image using command

"docker build -t devops . "

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

Launch a container using this image using command

"docker run -dit -p 8086:8080 --name jenkins devops:v2"

No alt text provided for this image

we can get the initial password of Jenkins using command

docker exec <container name> cat /var/lib/jenkins/secrets/initialAdminPassword" as shown above on the image.

now browse and access the Jenkins using Ip of base os and port no

192.168.43.199:8086

No alt text provided for this image

now complete setup is done of jenkins. so we can start creating job in jenkins

before start creating the job i have installed github , build pipeline, email Notification and job dls plugin in jenkins.

JOB-1

  • this is my seed job , it will create others job.
  • In job i am putting my github repository url in git section sp that i can download all the code uploaded by developer.
  • I am scheduling my job using pollscm it will go to github and check the information at every minute. if any new data will be uploaded by developer it will automatically download the code.
  • I am copying all the data in the folder /Devops6
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
  • in DSL script i have written Groovy code to create job2 and job3.
job("JOB-2") {
description("This job will launch the pods and deploy the code")

	triggers {  
	upstream('JOB-1', 'SUCCESS')
	}


  steps {
  shell('cd /devops6\nkubectl create -f webpage.yml\nsleep 15\npodename=$(kubectl get pods -o=name | grep webdeploy | sed "s/^.\\{4\\}//")\nkubectl cp /devops6/mycode  $podename:/var/www/html')
}

}



job("JOB-3") {


	triggers {  
	upstream('JOB-2', 'SUCCESS')
	}


 steps{

  shell('status=$(curl -o /dev/null -s -w "%{http_code}" https://192.168.99.110:32000/mycode/satyam.html)\nif [[ $status == 200 ]]\nthen\nexit 0\nelse\nexit 1\nfi')

}
  
    publishers {
        extendedEmail {
            recipientList('[email protected]')
            defaultSubject('Oops')
            defaultContent('Something broken')
            contentType('text/html')
            triggers {
                beforeBuild()
                stillUnstable {
                    subject('Subject')
                    content('Body')
                    sendTo {
                        developers()
                        requester()
                        culprits()
                    }
                }
            }
        }
    }

  
  
}

After creating job3 we need to configure email. for this go to configuration system and give some necessary information as given below.

No alt text provided for this image

All the job is completed, so I have created a build pipeline. my all three jobs are dependent to each other. so as soon as developer will push the code on github then job1 will automatically will start and other job also will start.

So here developer written code in a file webconfig.yml to deploy web page on the top of kubernetes.

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

and some others files that contain some html code

No alt text provided for this image

and then push it github repository

No alt text provided for this image

as soon as developer push the code to github job1 will trigger because pollscm checking information at every minutes.

No alt text provided for this image

here we can access our webpage using "<minikubeIP:32000"

No alt text provided for this image

JOB-2 created by seed job using groovy code

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

JOB-3 created by seed job using groovy code

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

console output of all the job

JOB-1

No alt text provided for this image

JOB-2

No alt text provided for this image

JOB-3

No alt text provided for this image

If job-3 will be failed

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

we will receive this type of mail on the email.

No alt text provided for this image

I have done with all the setup

Thank You for reading this article...................









Aman Kumar Abhishek

Student at ARTH - The School of Technologies

4 年

Now I became totally jealous from you guys Sulekha . Suhaib Ansari Satyam Kumar Rakesh Mishra Babli Singh

回复

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

Km Sulekha的更多文章

  • Docker GUI Task26

    Docker GUI Task26

    This article describe how we can launch GUI software on Docker. Task Description *GUI container* on the *Docker* Launch…

  • HotStar Case Study Task2

    HotStar Case Study Task2

    This article will describe the journey of Hotstar’s infrastructure from EC2 to Kubernetes. The journey about why, what,…

    1 条评论
  • Case Study of AWS SQS

    Case Study of AWS SQS

    In this article I am going to share what is Amazon SQS and industries use case of Amazon SQS. Amazon SQS Amazon Simple…

  • ARTH Task18

    ARTH Task18

    In this article we are going to explain how to we can configure WordPress on ec2 instances and connect this with Amazon…

  • Arth2020 Task17

    Arth2020 Task17

    In this article we are going to create chat program using python socket programming and Threading. Task Description…

    2 条评论
  • Create a setup so that you can ping google but not able to ping Facebook from same system Task13

    Create a setup so that you can ping google but not able to ping Facebook from same system Task13

    This article is to explain how we can create an interesting networking setup in which only we can reach to google but…

  • How big MNC's like Google , Amazon etc stores, manages and manipulate Thousands of Terabytpes of data with High Speed and High Efficiency Task-1

    How big MNC's like Google , Amazon etc stores, manages and manipulate Thousands of Terabytpes of data with High Speed and High Efficiency Task-1

    In a world where competition is intense, users will simply dump you, if your app slows down or freezes. So your…

  • Industries use case of AKS ?

    Industries use case of AKS ?

    Kubernetes is by far the most popular container orchestration tool, yet the complexities of managing the tool have led…

  • Ansible-Tower

    Ansible-Tower

    In this 3 hours of session we learn practical demo how industries are using Ansible-Tower and how it gives lots of…

  • Arth2020 task12

    Arth2020 task12

    This article is to explain how to configure a highly automated setup for Reverse proxy i.e Haproxy and update it's…

    5 条评论

社区洞察

其他会员也浏览了