We are going to deploy a webserver on the top of K8s, using jenkins DSL .Using jenkins DSL ,we can share,deploy out job very easily. Basically jenkinsfile is a textfile that have definition of jenkins Pipeline,It uses a Domain Specific Language(DSL) i.e, Groovy Language.
1)Create container image that’s has Jenkins installed using Dockerfile or you can use the Jenkins Server on RHEL 8.
2) When we launch this image, it should automatically starts Jenkins service in the container
3) Create a job chain of job1, job2, job3 & job4 using build pipeline plugin in Jenkins .
4) Job1 (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) Job2 : >> 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 ).
>> Expose your pod so that testing team could perform the testing on the pod .
>> 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 .
Pre-Requisites : i) Jenkins on Rhel-8 server ii) Minikube installed with Kubernetes configured
First we create docker Image using Dockerfile having configuration file of K8s,k8s certificates,etc.
Now our Dockerfile has been created,Now we have to build the Image.
docker build -t t-6:1 .
Now Our Image is created ,So we launch container
docker run -dit -p 3434:8080 --name task t-6:1
After launching the container we get the default password of the jenkins.
Then Install the required plugins :
- Job DSL
- Build pipeline
Now we are ready to create the seed job.It will clone our groovy script from github and from the script it will automatically create our job chain.But we have to disable the script security.
Seed job has been configured ,Now we have to just build the job.After the successfull build of the job we can see a new pipeline in our dashboard.So we just build the pipeline.
Job 1: It will launch pvc , deployment and nodeport service by looking at the code of the webpage and copy the web page in the pod .
Job 2: It will test if the web page is running or not with the help of status code received from the web server.
Job 3: It will automatically send a mail if the job 2 build is failed.
The Build pipeline:
THANK you !!