DevOps Assembly Lines Task #6

DevOps Assembly Lines Task #6

Task Description:

Deploy your website on kubernetes with the help of Jenkins coding file as follows:

1. Create container image that's has Jenkins installed using docker file 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 job 1, job 2, job 3 and job 4 using build pipeline plugin in Jenkins 

4. Job 1 ( Seed Job ) : Pull the GitHub repo automatically when some developers push repo to Github.

5. The remaining jobs should be written using Groovy language by the developer:

  • Job 2:  

  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 )

  • Job 3: Test your app if it is working or not.
  • Job 4: 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

Creating docker image with jenkins installed:

Docker file for jenkins image:

No alt text provided for this image

To use this file to create image:

>> docker build -t jenkinsenv:v1 /ws

The jenkins image is created successfully created.

Creating GitHub repository:

Commands to run to create a repository:

No alt text provided for this image

Index.html file:

No alt text provided for this image

The repository is created successfully:

No alt text provided for this image

Configuring Jenkins:

Job DSL plugin must be installed and some settings must be changed in our Jenkins system before we proceed.

No alt text provided for this image

Creating the seed job for running DSL:

No alt text provided for this image

DSL code to create the jobs:

job(‘t6_job1’){
description(‘This job will download the repository whenever developer makes any changes to it.’)
scm{
github(‘suchitrasaksena/DevOps_task6’)
}
triggers {
scm(‘* * * * *’)
upstream(‘seed_job’,’SUCCESS’)
}
steps {
shell(‘’’ if sudo cd /;ls | grep DevOps_task6
then
sudo cp -rvf * /DevOps_task6
else
sudo mkdir /DevOps_task6
sudo cp -rvf * /DevOps_task6
fi
‘’’)
}
}

job(‘t6_job2’){
description(‘This job will deploy the website on the required container’)

triggers {
upstream(‘t6_job1’,’SUCCESS’)
}
steps{
shell(‘’’ sudo cd /DevOps_task6
if ls | grep “.html”
then
sudo kubectl delete all — all
sudo kubectl create -f apache-pod-Deployment.yml
sudo kubectl create -f apache-pod-Service.yml
sudo kubectl create -f apache-pod-pvc.yml
sudo sleep 20
status=$(sudo kubectl get pods -o ‘jsonpath={.items[0].metadata.name}’)
sudo kubectl get all
sudo kubectl cp /DevOps_task6/Index.html $status:/var/www/html/
fi
‘’’)
}
}

job(‘t6_job3’){
description(‘This job will check if the website are working properly’)
triggers {
upstream(‘t6_job2’,’SUCCESS’)
}
steps{
shell(‘’’ if sudo kubectl get deploy | grep apache-pod-deploy
then
echo “Web Server running”
else
echo “Server not running”
fi
‘’’)

}
}
job(‘t6_job4’){
description(‘This job will send a mail to the developer if the website has any issue’)
triggers {
upstream(‘t6_job3’,’SUCCESS’)
}
publishers {
extendedEmail {
recipientList(‘[email protected]’)
defaultSubject(‘Webserver Issue’)
defaultContent(‘’’issues found in website’’’)
contentType(‘text/plain’)
triggers {
beforeBuild()
stillUnstable {
subject(‘Subject’)
content(‘Body’)
sendTo {
developers()
requester()
culprits()
}
}
}
}
}

buildPipelineView(‘DevOps_task6’) {
filterBuildQueue()
filterExecutors()
title(‘DevOps_task6’)
displayedBuilds(1)
selectedJob(‘seed_job’)
alwaysAllowManualTrigger()
showPipelineParameters()
refreshFrequency(60)
}

The seed job will successfully create the 4 jobs in a build pipeline view:

No alt text provided for this image

File for deploying the pods:

YML file to create service for Apache web server:

No alt text provided for this image

YML file to create PVC for Apache web server:

No alt text provided for this image

YML file to create Deployment for Apache web server:

No alt text provided for this image

The jobs run successfully and our website is deployed successfully:

No alt text provided for this image

The task is completed successfully. Thank for reading! Feel free to leave your reviews and suggestions to improve this setup.

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

Suchitra Saksena的更多文章

  • DevOps Assembly Lines Task #5

    DevOps Assembly Lines Task #5

    Task Description: Integrate Prometheus and Grafana in following way: Deploy them as pods on top of Kubernetes using the…

    4 条评论
  • DevOps Assembly Lines Task #4

    DevOps Assembly Lines Task #4

    Task Description: Create A dynamic Jenkins cluster to achieve this setup: Create container image that’s has Linux and…

  • DevOps Assembly Lines Task #3

    DevOps Assembly Lines Task #3

    Task Description: Create container image that’s has Jenkins installed using docker file. When we launch this image, it…

  • DevOps Assesmbly Lines Task #2

    DevOps Assesmbly Lines Task #2

    Task Discription: Create container image that has Jenkins installed using dockerfile. When we launch this image, it…

  • DevOps Assembly Lines Task #1

    DevOps Assembly Lines Task #1

    Task Description : JOB 1 If Developer push to master branch then Jenkins will fetch from master and deploy on "Deploy"…

    4 条评论

社区洞察

其他会员也浏览了