3

I am testing a connection between a persistent volume and a kubernetes pod by running busybox, but am getting "can't open" "no such file or directory. In order to do further testing, I tried running

echo ls /mntpoint/filename

This is obviously not the correct command. I have tried a few other iterations - too many to list here.

I want to run ls of the mountpoint and print to the console. How do I do this?

EDIT

My code was closest to Rohit's suggestion (below), so I made the following edits, but the code still does not work. Please help.

Persistent Volume

apiVersion: v1
kind: PersistentVolume
metadata:
  name: data
  labels:
    type: local
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: "/mnt/data"
  storageClassName: test

Persistent Volume Claim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: test

Pod

apiVersion: v1
kind: Pod
metadata:
  name: persistent-volume
spec:
  containers:
    - name: busybox
      command: ['tail', '-f', '/dev/null']
      image: busybox
      volumeMounts:
        - name: data
          mountPath: "/data"
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: data

EDIT 2

So, after taking a day off, I came back to my (still running) pod and the command (ls) worked. It works as expected on any directory (e.g. "ls /" or "ls /data").

My current interpretation is that I did not wait long enough before running the command - although that does not seem to explain it since I had been monitoring with "kubectl describe pod ." Also I have run the same test several times with short latency between the "apply" and "exec" commands and the behavior has been consistent today.

I am going to continue to keep playing with this, but I think the current problem has been solved. Than you!

user3877654
  • 1,045
  • 1
  • 16
  • 40
  • 1
    Once your pod is running, use `kubectl exec` to get inside the pod and then whatever `ls` command you want to. https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/ – mchawre Aug 07 '20 at 16:49
  • @mchawre Thank you for your reply. When I try "kubectl exec persistent-volume -- ls /" I get no response. I am interpreting this as the command being run on busybox, but not giving me its output. Is this not the correct interpretation? – user3877654 Aug 07 '20 at 20:32
  • --1. Please use different commands inside your pod like: `command: [ "/bin/sh", "-c", "sleep 3000"]`, use interactive shell : `kubectl exec -it persistent-volume -- /bin/sh` and use `ls` to list all files. --2. Verify that your pod is up and running. -- 3. Verify pv,pvc binding `kubectl get pv,pvc`. $. Verify that any files exists inside your hostpath ` path: "/mnt/data" ` --4. Verify if your pod was scheduled on the proper node according to created /mnt/data on the same node. Please provide results of your your investigation. – Mark Aug 10 '20 at 09:47

2 Answers2

1

We cannot directly access volume mount on the POD without create a claim. You are missing some steps here.

  1. Create a Persistent Volume. I think you have done this par.
  2. Create Persistent Volume Claim. This will bind your claim to your volume.
  3. Attach your Persistent Volume Claim to the pound.

Once these steps are done you can access the files from your volume in the pod.

Go through the link for detailed information and steps.

Rohit
  • 1,231
  • 10
  • 22
  • Thank you for your suggestion, but I still cannot get my code to work. :( – user3877654 Aug 07 '20 at 20:31
  • 1
    What error you are getting, please paste here. I tried with the same configuration what you have provided in the question and I'm able to do ls / or ls /data. – Kiruba Aug 08 '20 at 09:39
1

Steps you need to follow when dealing with volumes and Kubernetes resources:

  1. Create a Persistent volume.
  2. Create a Persistent volume claim and make sure the state is bound.
  3. Once the PV and PVC are bounded, try to use the PV from a pod/deployment through PVC.
  4. Check the logs of the pod/deployment. You might see the entry of command execution.

Reference: https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/

Hope this helps, please try to elaborate more and paste the logs of above-mentioned steps.