DevOps AL- Task 3: Managing and Deploying Webserver/App using Jenkins & Docker on top of Kubernetes

DevOps AL- Task 3: Managing and Deploying Webserver/App using Jenkins & Docker on top of Kubernetes

PROBLEM STATEMENT: Perform this task on top of Kubernetes, where we use Kubernetes resources like Pods, ReplicaSet, Deployment, PVC, and Service.

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 start the Jenkins service in the container.

3) Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins 

4) Job1: Pull the Github repo automatically when some developers push the repo to Github.

5) Job2: a) 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 ). b) Expose your pod so that the testing team could perform the testing on the pod. c) Make the data to remain persistent ( If server collects some data like logs, other user information )

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

7) Job4: If the app is not working, then send email to the developer with error messages and redeploy the application after code is being edited by the developer

ASSUMPTIONS: VirtualBox is installed for virtualization.RHEL 8 VM is already setup and configured. The VM must have internet connectivity. The base system must have Internet connectivity. The Base system, here Windows must have Kubernetes setup in CLI. Jenkins must be set up in RHEL8 VM and Docker as well. Git bash is installed in Windows. Having a GITHUB account is important.

STEPS:

No alt text provided for this image

STEP 1) Launch Git Bash. Create a folder, here Github. In it clone the Github repository which will contain our code for this task.

To clone use the Github Repository URL. This will clone all the files from that repository to a folder with the same in the Github folder.

No alt text provided for this image

Use the ls command to check if the files are closed properly.


No alt text provided for this image

Create a post-commit trigger, which will not only push the code to Github automatically after each commit. But also Build the initial job1 on Jenkins. For it provide the URL of the git and password of Jenkin's account.

No alt text provided for this image

STEP 2) Launch the RHEL8 node, which will be the host for Docker. Create a folder here, for Dockerfile. This folder must also have ca.crt,client.crt,client.key, and config file of minikube aka Kubernetes running on Windows. Copy these files using WinSCP.These files are needed to Kubernetes in Docker containers.

No alt text provided for this image

This is code for the docker image which will setup Jenkins server and also Kubernetes in our container. Copy the certificates and config file to this image. Expose command will expose the container. This is my config file.

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

STEP 3) Check docker status. Make sure its running and enabled.




No alt text provided for this image

STEP 4) Build the image




No alt text provided for this image

Make sure the image is properly built.

Now launch a container using this image. Provide the port number using patting so that it can be accessed outside. And also mount a folder to keep data persistent even if the container collapses.

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

STEP 5) Now connect to the Jenkins server using VM IP:9999. Login Using your Jenkins account.



No alt text provided for this image

Run this command to check if Kubernetes is properly set up in the container.

No alt text provided for this image

This is what my Github repository looks like for this task with all necessary files.

No alt text provided for this image

STEP 6) Create job1 now. Provide the Github Repository URL for SCM. This will be the initial job. Add build other projects trigger which will trigger build on job2. This job1 will be triggered automatically whenever the user will commit code.

No alt text provided for this image

Created a service.yml file that will create a service. Knowledge of service helps in planning architecture in Kubernetes.

Created pvc.yml file which will create a Persistent Volume Claim, which keeps data persistent. It can be mounted to any container.PVC creates PV dynamically.

Create httpd.yml and php.yml file which will launch pods for HTTP and PHP respectively, when run.

STEP 7) Create job2 and write the following code. This code will launch a service if the service isn't launched already. Launched a PVC. It will also launch a pod, based on our code. If our code is .php then a PHP pod will be launched using a php.yml file. If the code is .html then HTTP pose will be launched using httpd.yml file, as provided.

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


This job will also trigger job3, which will check for if the code runs successfully or not.

STEP 8) the job4 will check for the validity of the code by using the status of the code. If the page returns code 200 that means it runs successfully, otherwise the build fails. Also, add a parameterized trigger that builds other projects based on parameters specified. Here this job3 builds job4 only when it fails or is unstable.

No alt text provided for this image

STEP 9) The final job that is job4 will send the email notification to the user when the app/webserver isn't working. For this download, the Email plugin and Email-extension plugin which will help in system-generated emails, which can be customized. Here provide the recipient email address. Also write any customized message or text which you want to send in email, regarding the unsuccessful deployment of app/webserver.

No alt text provided for this image

CONCLUSION 1) Since we provided .html file that is tanya.html file, so on successful built of job1 and job2 httpd pod will be launched with service and PVC setup. On running kubectl get all command we can see out httpd pod deployed with our HTML code and exposed as well. Which can be checked using IP:Portnumber

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

Since our code is correct so it job1,job2 and job3 will be built successfully. Thus deploying our html page.Job4 won't be triggered. Here is my build pipeline for html successful build.

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

CONCLUSION 2) Here I provided a PHP file-tanya.php as well. The job1,job2,job3 will run successfully when the code is right.Job4 won't be triggered since our code runs successfully, returning status 200.php pod will be launched for this.

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

The site will be successfully deployed.




No alt text provided for this image

But when we make some wrong updation to this PHP code, and commit this code to Github. It will trigger job1 and job2 and they will be built successfully, but job3 will fail, since the code wasn't right thereby returning status other than 200.

Here job4 will be triggered now since job3 fails. Thus the user will receive a message for the unsuccessful build.

No alt text provided for this image

This is what Build Pipeline will look like when the app/webserver fails.

No alt text provided for this image

That's it. Task 3 is done!

I tried to implement both the scenario -for PHP and HTML. I hope I was able to cover every part of the Problem Statement. Thank you!

Here is the link to my Github Repository which contains service.yml, pvc.yml, httpd.yml, and php.yml files: https://github.com/TanyaChetnaVaish/devaltask3


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

Tanya Chetna Vaish的更多文章

社区洞察

其他会员也浏览了