https://rancher.com/ logo
a

adamant-france-62364

12/29/2022, 12:24 PM
I want to mount
/Users/$USER/.aws
in my containers, given that
/Users/$USER
is mounted in the host node by default. Is there a way to express this in the Pod's volume and container's volumeMount generically? The problem being that the value of $USER is not known in the cluster. A few ideas: • Use mountPoint in overlay.yaml to elide the $USER
Copy code
mounts:
- location: "~/.aws"
  mountPoint: /user-aws
• Use subPathExpr in volumeMount in combination with $USER env var
Copy code
volumeMounts:
- name: users # /Users
  subPathExpr: $(USER)/.aws
• Use helm or kpt to substitute Other ideas?
👍 1
b

bitter-hairdresser-7812

12/29/2022, 10:17 PM
Hrm, that substitution ought to work. Would love to get a solution For others learning check out this example https://itnext.io/simplest-basic-k8s-tutorial-to-mount-local-host-directory-into-a-pod-volume-example-with-rancher-18b4f1d75cd9
a

adamant-france-62364

12/29/2022, 10:24 PM
Thanks. The
subPathExpr
approach does work, and that's what we're going with now. I haven't tried changing/adding a
mountPoint
in
overlay.yaml
. For one thing, mountPoint is barely documented, but I can see it in the source code.
🦜 1
An example with a volume and volume mount:
Copy code
spec:
  containers:
  - name: example
    envFrom:
    - configMapRef:
        name: user # USER=
    volumeMounts:
    - name: users
      mountPath: /some/path
      subPathExpr: $(USER)
      readOnly: true
  volumes:
  - name: users
    hostPath:
      path: /Users
      type: Directory
👍 1
23 Views