Follow these steps to provision Kubernetes agents on a separate cluster from the managed controller.
| Starting with CloudBees CI version 2.263.4.1, the steps below can be used to define a Kubernetes Shared Cloud. When defining the Kubernetes Shared Cloud, leave the Jenkins URL empty so the controller that consumes the Shared Cloud can infer it based on its public URL. |
To deploy agents in a separate Kubernetes cluster from the managed controller:
-
Set up kubectl to point to the target agent cluster.
-
Type the following command to install only
serviceaccount/jenkinsand the related role and role binding:helm install <helm deployment name> cloudbees/cloudbees-core --set OperationsCenter.Enabled=false --set Agents.SeparateNamespace.Enabled=true --set Agents.SeparateNamespace.Create=trueThe
serviceaccount/jenkinshas the required Kubernetes RBAC permissions to provision and manage pods in a namespace. This is required to provision Kubernetes agents in a specific namespace.These configurations may be adjusted for extended requirements, such as the creation/deletion of PVCs if you use the dynamic PVC feature of the Kubernetes plugin.
-
Type the following command:
The Krew plugin manager is required to run this command. kubectl krew install view-serviceaccount-kubeconfig -
Type the following command:
kubectl apply -f - <<EOF apiVersion: v1 kind: Secret type: kubernetes.io/service-account-token metadata: name: jenkins-external annotations: kubernetes.io/service-account.name: jenkins EOF kubectl view-serviceaccount-kubeconfig jenkins > /tmp/sa-jenkins.yaml -
Select in the upper-right corner to navigate to the Manage Jenkins page.
-
Select Clouds.
-
Using the service account on your managed controller, select Add a new cloud, and then select Kubernetes.
-
Enter a Name of your choice, and then select Kubernetes Cloud details.
-
In Credentials, add a Secret File credential type, and then upload the sa-jenkins.yaml file that you created in step 4.
-
Select WebSocket.
-
In Jenkins URL, enter the public ingress URL of the managed controller.
-
Leave all other fields blank.
-
Select .
-
Enter a pod template name.
-
Select Pod Template details.
-
In Labels, enter the label of the pod.
-
The Labels field of the pod template is used to select the template in a Pipeline, and is not the name. Therefore, it is important to enter the pod label in the Labels field.
-
You do not have to add a static pod template if you plan to use the
podTemplatestep exclusively to define templates dynamically from builds.
-
-
Select Save.