0

As far as i understood, the kubernetes api allows one to mount a subpath of a pvc into the container in the volumeMounts spec.

In my example i want to mount the pvc my-pvc, but in the subdirectory /my-subpath to /my-mount.

So the directory /my-subpath on my-pvc would be mounted in the container under /my-mount.

When using Kubernetes normally, this would look like follows if i understood the docs:

volumeMounts:
- mountPath: /my-mount
      name: my-pvc
      subPath: "my-subpath"

My problem now is, that in the jenkins kubernetes plugin this doesn't seem to be possible.

If i understood the docs correctly, it seems that it is only possible to mount the root directory, i.e. /, of the pvc my-pvc to /my-mount in the container, since there is no subPath option: Jenkins documentation screenshot

Is there something i am missing, or is it just not possible to do this?

Mark G
  • 250
  • 4
  • 10
  • I'm not very sure about what you're after but just to clarify, is `my-subpath` a sub-dir of `/my-mount`? – Technext May 28 '20 at 09:50
  • Usually the volume is mounted from root, i.e. `/`, to `/my-mount` as i understood it. I want to mount `/my-subpath` to `/my-mount`. – Mark G May 28 '20 at 09:55
  • Can you try replacing existing values with the one specified here? `- mountPath: /my-mount/my-subpath` & `subPath: my-subpath`. Also notice that value of `subPath` doesn't contain `/` at the beginning. – Technext May 28 '20 at 10:02
  • I'm sorry if my description is a bit unclear. I'm not trying to mount to `/my-mount/my-subpath`. The problem is, that the jenkins kubernetes plugin api does not have a `subPath` (see the doc screenshot), or is it just not documented? – Mark G May 28 '20 at 10:06
  • As I understand you want to mount `/pvc/my-subpath` inside your container as `/my-mount`. Am I correct? – hariK May 28 '20 at 12:02
  • Yes @hariK, I belive that this is what OP is trying to do and he also knows how to do it with k8s. The question here is "how to use subpath in jenkins", which apparently doesn't support this functionality. – Matt May 28 '20 at 12:45
  • @HelloWorld Yes that is what i am trying to do and what my problem is. – Mark G May 28 '20 at 13:58

1 Answers1

0

It is not possible by available options of Jenkins Kubernetes plugin ATM. But still, you can achieve this by applying a raw pod template in Kubernetes cloud pod configuration.

Sample output

Started by user admin
Replayed #11
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
‘hello-docker-j0rk6’ is offline
Agent hello-docker-j0rk6 is provisioned from template hello-docker
---
apiVersion: "v1"
kind: "Pod"
metadata:
  annotations: {}
  labels:
    run: "hello-docker"
    jenkins: "slave"
    jenkins/label: "hello-docker"
  name: "hello-docker-j0rk6"
spec:
  containers:
  - command:
    - "cat"
    image: "jenkins/jnlp-slave:3.27-1-alpine"
    name: "hello-docker"
    resources: {}
    tty: true
    volumeMounts:
    - mountPath: "/app/logs"
      name: "tmp"
      subPath: "logs"
    - mountPath: "/home/jenkins/agent"
      name: "workspace-volume"
      readOnly: false
hariK
  • 2,722
  • 13
  • 18