Sharing Persistent Volume between Jenkins Master and Slaves

Solution Verified - Updated -

Environment

  • Red Hat OpenShift Container Platform 3.7

Issue

  • We use Jenkins pipelines deployed in OpenShift. We would like to use a persistent volume shared between the Jenkins master and the Jenkins slaves in order to share data between them.

  • How can we modify the Jenkins configuration in order to achieve this?

Resolution

In order to share a PV between 2 pods, the pod definition needs to reference the same Persistent Volume Claim name. There are more details on this in the "Sharing an NFS mount across two persistent volume claims" section of the OpenShift Container Platform 3.7 documentation.

Slave pods use ephemeral storage by default. However, it is possible to configure persistent storage for the slave pods from the Jenkins console: Manage Jenkins > Configure System > Cloud > Kubernetes > Images > Kubernetes Pod Template > Volumes

A new volume can be added by clicking on "Add Volume", selecting the "Persistent Volume Claim option" and adding the Claim Name from the existing Jenkins persistent instance. This can be found in the Jenkins deployment configuration (oc get dc/jenkins -o yaml) under volumes > persistentVolumeClaim > claimName. For example

      volumes:
      - name: jenkins-data
        persistentVolumeClaim:
          claimName: jenkins

It is also possible to configure this by using a ConfigMap as per the "Using the Jenkins Kubernetes Plug-in to Run Jobs" section in the OpenShift Container Platform 3.7 documentation.

For example, within the ConfigMap, it is possible to add a volumes section within the PodTemplate section xml:

  apiVersion: v1
  items:
  - apiVersion: v1
    data:
      jenkins-slave-template: |-
        <org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
          .
          .
          .
          <volumes>
            <org.csanchez.jenkins.plugins.kubernetes.volumes.PersistentVolumeClaim>
              <mountPath>MOUNT_PATH_FOR_SLAVE_DATA</mountPath>
              <claimName>PERSISTENT_VOLUME_CLAIM_NAME</claimName>
              <readOnly>false</readOnly>
            </org.csanchez.jenkins.plugins.kubernetes.volumes.PersistentVolumeClaim>
          </volumes>
          .
          .
          .
        </org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
    kind: ConfigMap

A list of all of the available configuration options can be found in the jenkins-kubernetes-plugin GitHub repository README

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.