1

I am trying to mount a directory called rstudio which is residing in /mnt/rstudio. But when I try to mount using persistent volume, the directory is showing up but not the files inside rstudio. Here's my deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: rsp-deployment
spec:
  selector:
    matchLabels:
      app: rsp
  replicas: 1
  strategy: {}
  template:
    metadata:
      labels:
        app: rsp
    spec:
      nodeSelector:
        kubernetes.io/hostname: testserver.local
      volumes:
       - name: rsp-persistent-storage
         persistentVolumeClaim:
           claimName: pv-claim-rsp
      containers:
      - env:
        - name: RSP_LICENSE
          value: MY LICENSE
        image: rstudio/rstudio-server-pro:latest
        name: rstudio-server-pro
        ports:
        - containerPort: 8787
        - containerPort: 5559
        volumeMounts:
         - name: rsp-persistent-storage
           mountPath: /tmp/rstudio
        resources: {}
        securityContext:
          privileged: true
      restartPolicy: Always
status: {}

---
kind: Service
apiVersion: v1
metadata:
  name: rstudio-server-pro
spec:
  selector:
    app: rsp
  ports:
  - protocol: TCP
    name: "8787"
    port: 8787
    targetPort: 8787
  type: NodePort

And my pv and pvc files are as follows

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-volume-rsp
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/rstudio"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-rsp
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi

Inside my /mnt/rstudio there are these much files.

[root@test-server rstudio]# ls
launcher.conf                      launcher-mounts          launcher.pub        rserver.conf  
launcher.kubernetes.conf           launcher-mounts_working  logging.conf        rsession.conf 
launcher.kubernetes.profiles.conf  launcher.pem             notifications.conf  r-versions

But after the pod is up and running, the directory is showing empty. Any idea why? Thanks in advance!

Sam
  • 5,375
  • 2
  • 45
  • 54
Siddharth
  • 192
  • 3
  • 20
  • do you want to try defining `type: Directory` inside of `hostPath:` for your PV – user2932688 Aug 18 '20 at 14:14
  • It says we can't have type:Directory defined in the persistent volume file – Siddharth Aug 18 '20 at 14:21
  • i see, that means you PV should be `path: "/mnt/rstudio/"` - note `/` at the end :) – user2932688 Aug 18 '20 at 14:52
  • I added / . PV created. But still, it doesn't have files inside the folder rstudio. – Siddharth Aug 18 '20 at 14:57
  • when you dropped whole deployment - did you check that pvc is also gone? like this `kubectl get pvc` and `kubectl get pv`. i've seen that pvc may be still there. so i would recommend drop everything. Make sure everything is gone including `pvc` and `pv`. then do change to pv and recreate everything back. – user2932688 Aug 18 '20 at 15:01
  • Yes, every time I try re-deploying, I used to delete all pv and pvc and run it again from scratch. – Siddharth Aug 18 '20 at 15:03
  • I reproduced your deployment with no issues. Are you sure you are checking `/tmp/rstudio` inside the pod and files are present on `testserver.local` node? – kool Aug 19 '20 at 11:52

2 Answers2

3

LGTM. I am getting files if I swap the image with nginx. I would check two things:

  1. Permissions: Check what permissions the files have. You may have to update your permissions or UID to access the files.
  2. Does rstudio image use that path? It may be processing that folder when it starts. Try mounting to a different path and see if you can see the files.

Also, make sure you are launching the pod on the node where the host path exists. I am assuming testserver.local and test-server are the same.

HTH

Faheem
  • 3,429
  • 19
  • 26
  • Files have rw permssions. RStudio doesn't use that path. That's why I redirected it to /tmp. And yes, I am launching the pod where hostpath exists.@Faheem – Siddharth Aug 18 '20 at 14:58
  • Does is `rw` for all? Who is the owner? What user are running with inside the container. Configuration you have is working for me. It's something your environment. – Faheem Aug 18 '20 at 18:58
  • 1
    I resolved this issue. "Also, make sure you are launching the pod on the node where the host path exists. I am assuming testserver.local and test-server are the same."" This point was the thing. – Siddharth Aug 24 '20 at 15:44
  • I have a question- What is the best way to mount a directory if testserver.local and test-server are 2 different servers? Which method is the best? – Siddharth Aug 24 '20 at 15:45
  • Ideally, the storage should be separate from the nodes hosting containers. Think NFS or data disks. If you want to use the local disk, consider using `nodeAffinity` and `nodeSelector` like attributes for consistency. See the answer of this question -> https://stackoverflow.com/a/60283134/54354 – Faheem Aug 24 '20 at 16:08
0

Does you PVC make use of the PV you created? Check it with

kubectl get pvc

Try adding a label to the pv and use a matchLabels selector to make sure the PVC actually consumes the PV you just created:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-volume-rsp
  labels:
    name: pv-volume-rsp  # Added
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/rstudio"

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-rsp
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      name: pv-volume-rsp  # Added 
Sam
  • 5,375
  • 2
  • 45
  • 54