How to integrate Jenkins and kubernetes
Here I am show you how to integrate kubernetes with jenkins . You can read this comment for better
Before integration you have to do some settings. I have installed jenkins on RHEL 8 and to integrate with kubernetes cluster we first have to download the kubectl on RHEL 8 because kubectl is the one who manages the kubernetes cluster. Before downloading we first set up two network card on RHEL 8 one is NAT and other is Host only Adapter. We use Nat network card for internet connectivity and Host only network card to connect with kubernetes cluster. For integration it is to be kept in mind that kubectl and jenkins should be installed on same operating system. My kubernetes cluster is running on minikube vm .
After this we download kubectl for linux.
To activate kubectl we use chmod then we move this kubectl to /usr/bin so that we can use this from anywhere.Then we try to get information of pods but some error is coming up .This error is showing because to do connectivity with kubernetes cluster we have to specify the ip of kubernetes and on which port it is running after this we have to give client-key it is like a password, client-certificate it is like a user and a certificate for authentication purpose.We can copy all these files from below path
For copying these files from windows to RHEL we can use winscp. Now we can use kubectl on RHEL 8 to connect to kubernetes cluster. but we have to write this long command every time to get rid of this we can do one thing we create a config file and put all this server,clent,certificate information in that file.
We copy this config file to a folder called kube and in kube to config file by doing this we can directly give the command like kubectl get pods .Now our setup is done is done we can interact with kubernetes cluster without any problem . Lets do some automation with jenkins.
What i am doing here is integrating the jenkins with kubernetes. As soon as the developer upload the yaml file of replica set the jenkins will download this file and create one replicaset . Let me first upload the replicaset file to github.
After developer upload the file jenkins will download the file .For this we created a job that will contact to github we can use any trigger herei use poll scm .
Now jenkins check the replicaset is already running or not ,if not then create one replicaset after this it will also check that the rs is exposed to outside world or not , if not then expose this. In this replica set we have set 2 replica for a pod.
we can see on RHEL 8 that the rs is running fine or not and also check the service
See all the pods are running fine and the services is also created .
The automation has been completed .
Thank you for reading this article.
MLOps Engineer | 7x GCP | Kubernetes | Terraform | AWS | DevOps | Java | Python
4 年Great Work ..!