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:
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:
Index.html file:
The repository is created successfully:
Configuring Jenkins:
Job DSL plugin must be installed and some settings must be changed in our Jenkins system before we proceed.
Creating the seed job for running DSL:
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:
File for deploying the pods:
YML file to create service for Apache web server:
YML file to create PVC for Apache web server:
YML file to create Deployment for Apache web server:
The jobs run successfully and our website is deployed successfully:
The task is completed successfully. Thank for reading! Feel free to leave your reviews and suggestions to improve this setup.
Software Engineer III @Walmart | LNMIIT'22
4 年Great work Suchitra Saksena