Dynamic Jenkins agent in Kubernetes

Continuing the article about installing Jenkins in kubernetes, we will setup a dynamic agent for jenkins so that when we build the application, jenkins will launch pod automatically and build our application under the kubernetes. For this to work, you should have this following condition:

  • Jenkins installed in Kubernetes (you can follow this article)
  • Kubernetes plugin for jenkins

Install Kubernetes Plugin

Go to Dashboard ⟶ Manage Jenkins ⟶ Manage Plugins ⟶ Available Tab, select kubernetes plugin
Click Download and restart

Plugin Setting

Go to Dashboard ⟶ Manage Jenkins ⟶ Manage Nodes & Clouds ⟶ Configure Clouds, click add new Clouds.
In the Kubernetes Cloud details. Check the Websocket checkbox, if you want to run agent in the same kubernetes cluster. Test the connection, it should be connected to the kubernetes.
In the Jenkins URL, you should put the address of your jenkins server, if you want to use internal kubernetes domain name, you can use a format address like this: deployment-name.namespace.svc.cluster.local:8080, above example shows that jenkins installed in kubernetes as jenkins in jenkins namespace.

Next, in the Pod label section, put "POD_LABEL" as key and "my-jenkins-agent" as value.

That's it, save and try to run a pipeline, the job should be running in the kubernetes.

Resources:


Comments

Popular Posts