Automation of Kubernetes with Jenkins and docker using jenkins image
Krishna Sharma
Apigee API Developer|API Management|Kong API Gateway|Kubernetes Certified|Microsoft Azure|DevOps
what is Kubernetes?
Kubernetes (also known as k8s ) is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications.
In other words, you can cluster together groups of hosts running Linux containers, and Kubernetes helps you easily and efficiently manage those clusters.
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 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.
How to build Dockerfile?
docker build -t <image_name> <Dockerfile_directory> ex- docker build -it kubernetes:1.0 /root/mydockerfile
Now we have to launch the image
docker run -dit -p 9090:8080 --name kube -v /root/ymlfiles:/host -v /root/kubeconf:/root/.kube
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
Job1 :
Pull the Github repo automatically when some developers push repo to Github.
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 C) Make the data to remain persistent ( If server collects some data like logs, other user information )
Job3 :
Test your app if it is working or not.
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.
Job1 :
Pull the Github repo automatically when some developers push repo to Github.
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 ( If server collects some data like logs, other user information )
Add these commands in Excute Shell option in jenkins job which will create deployment.
yml file for crating deployment & PVC for applications file having .html extension
Deployment of html
Here is my Job2 Output
Here in the above services like pv,pvc and deployment has been created in k8s
Job3 :
Test your app if it is working or not.
We need to generate app password for sending the mail
If this job will be fail then it wail send email to developer .
After see this emai, developer debug the code , again commit it , then again It will be pushed to GitHub & again there will be redeployment of application inside k8s pods , for that w eanalso use:
- deployment strategies in k8s like rolling-updates for roll-out , roll-in concept.
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.
The final web-application running inside k8s pods(html file)
Apigee API Developer|API Management|Kong API Gateway|Kubernetes Certified|Microsoft Azure|DevOps
4 年Sure...!!! I will help you as much as i can :)
Associate Tech Lead - DevOps || AWS || Azure || GCP || Linux || Terraform || Jenkins || Docker || CI/CD || Kubernates || AWSCodepipeline ,Azure devops
4 年I want to learn CI/CD and k8s, Jenkins.. Can you please help me out?