Adding manual Jenkins Agents through Helm

8/28/2019

I've started an instance of a Jenkins Master using the official Helm chart. The document does provide values to be set for an agent. But how can I add agents manually through this chart?

The documentation within the "Agent" section shows the installation step

$ helm install --name my-release -f values.yaml stable/jenkins

But that's the same command for setting up a master node. Should the values be set in a way to convey the intent of setting up an agent instead of a master node?

(I'm aware of the Jenkins Kubernetes plugin for creating dynamic nodes but I need to add a static/manual node).

-- user6123723
jenkins
kubernetes
kubernetes-helm

1 Answer

9/2/2019

Took me a bit to figure this out.

It appears that when you specify an agent configuration, in the helm chart, then a "cloud" configuration is enabled which uses the Kubernetes plugin to run slave nodes as pods. Personally I prefer to enable the Jenkins as Code plugin and explicitly configure the pods I want to run. For example:

      JCasC:
        enabled: true
        pluginVersion: 1.23
        configScripts:
          cloud-config: |-
            jenkins:
              clouds:
              - kubernetes:
                  containerCapStr: "10"
                  jenkinsTunnel: "jenkins-test-agent:50000"
                  jenkinsUrl: "http://jenkins-test:8080"
                  maxRequestsPerHostStr: "32"
                  name: "kubernetes"
                  namespace: "jenkins"
                  serverUrl: "https://kubernetes.default"
                  templates:
                  - name: mycompany-base
                    label: mycompany-base
                    yaml: |-
                      apiVersion: v1
                      kind: Pod
                      spec:
                        containers:
                        - name: skaffold
                          image: gcr.io/k8s-skaffold/skaffold:v0.33.0
                          command:
                          - cat
                          tty: true
                          volumeMounts:
                          - name: docker-sock
                            mountPath: /var/run/docker.sock
                        volumes:
                        - name: docker-sock
                          hostPath:
                            path: /var/run/docker.sock
                            type: ""
                  - name: mycompany-go
                    label: mycompany-go
                    inheritFrom: mycompany-base
                    yamlMergeStrategy: merge
                    yaml: |-
                      apiVersion: v1
                      kind: Pod
                      spec:
                        containers:
                        - name: go
                          image: golang:1.11-stretch
                          command:
                          - cat
                          tty: true

I haven't tried but I'm sure you could use the same technique to configure a normal SSH based slave to be run. The JasC plugin is designed to enable you to automatic things we can normally setup via the UI.

-- Mark O'Connor
Source: StackOverflow