DEVOPS TASK 3 JENKINS INTEGRATION WITH KUBERNETES
Amit Sharma
CKA || 1xAWS || 4xGCP || 1xAzure || 2xRedHat Certified || DevOps Engineer [???????]@Searce Inc || Freelancer || Terraform || Ansible || GitLab || Jenkins || Kubernetes || Docker || Openshift || AWS || GCP || Azure
Hello Guys back with another article. In this article you will find jenkins intergration with Kubernetes.
What is Kubernetes ?
Kubernetes is an open-source container-orchestration system for automating application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation . In simple words, it's a management tool for container technology like docker, podman, CRI-O etc. We have some other orchestration tools like Swarm(by docker) etc, but kubernetes gives more flexibility in managing container with it's resources.
Task Description:
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 job 1, job 2, job 3 and job 4 using build pipeline plugin in Jenkins
4. Job 1 : Pull the GitHub repo automatically when some developers push repo to GitHub.
5. 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 ( If server collects some data like logs, other user information )
6. Job 3 : Test your app if it is working or not.
7. 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 .
Task Requirement --> we have installed minikube, which install a virtual machine which has kubernetes Installed.
Now your kubernetes cluster has been started, now you need another vm, I've use rhel 8. Here we're using docker to launch our kubectl client and jenkins server, for which we have created image using Dockerfile, as:
docker build -t my_jenkins /jenkins_docker/.
The above command will create a dockerimage. After that you need to make a cofig file inside /root/./kube/config.
After that do configuration in below file.
vim /usr/lib/systemd/system/docker.service after that reatrt tocker and reload daemon
systemctl daemon-reload systemctl restart docker
Then we have to create a dockerfile of jenkins.
docker build -t jenkins_server:2 /jenkins_docker/. ----> create image docker run -dit -v /jenkins_ws:/jenkins_ws -p 8080:8080 -e DOCKER_HOST=192.168.99.104:4243 --name jenkins_portal jenkins_server:2-->create OS
Now, we'll install some plugins in jenkins,
- Git plugin .
- GitHub plugin .
- Build pipeline plugin .
Now we've everything to start our practical, So let's begin with steps to configure deployment with CI/CD and Kubernetes . Open Jenkins and follow along,
Step 1:
Job 1 : This job will pull code from GitHub :
Step 2:
Job 2:- This job will detect code, either php or html and run kubectl client container with image created before and run Kubernetes pod with required interpreter .
Step 3:
Job 3:- this job will simply check the http status code of website , checks if environment is running or not .
Yay !! We have done with task 3.
Github Link: https://github.com/amit17133129/DEVOPSTask3/tree/master
I hope you will find this article interesting !!
ThankYou!
___________________________
4 年Great work buddy