access minikube folder's data from host machine

12/19/2021

I'm using minikube for running my Kubernetes deployment:

pvc:

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

pod:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test1
  name: test1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test1
  template:
    metadata:
      labels:
        app: test1
    spec:
      containers:
      - env:
        - name: SHARED_FOLDER_PATH
          value: /data/shared
        image: docker.io/foo/test1:st3
        imagePullPolicy: Always
        name: test1
        ports:
        - containerPort: 8061
          name: protobuf-api
        - containerPort: 8062
          name: webui
        volumeMounts:
        - mountPath: /data/shared
          name: test1
      imagePullSecrets:
      - name: acumos-registry
      volumes:
      - name: test1
        persistentVolumeClaim:
          claimName: pipeline

I have checked that pod and pvc are running:

$ kubectl describe pv,pvc

Name:            pvc-34bbd532-9c55-45cc-ab96-1accd08ded6e
Labels:          <none>
Annotations:     hostPathProvisionerIdentity: c6eeb812-6b82-4546-bc5a-8917cf0d3d6b
                 pv.kubernetes.io/provisioned-by: k8s.io/minikube-hostpath
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    standard
Status:          Bound
Claim:           test/pipeline
Reclaim Policy:  Delete
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        1Gi
Node Affinity:   <none>
Message:         
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /tmp/hostpath-provisioner/test/pipeline
    HostPathType:  
Events:            <none>

What I'm trying is to access the data on the minikube folder: /tmp/hostpath-provisioner/test/pipeline from host machine. For that purpose, I'm mounting local volumen:

$ minikube mount /tmp/hostpath-provisioner/test/pipeline:/tmp/hostpath-provisioner/test/pipeline

I have checked if any data is on minikube folder by ssh:

docker@minikube:/tmp/hostpath-provisioner/test/pipeline$ ls -a

.  ..  classes.json

But I can't see this info from local folder

-- rluq
kubernetes
kubernetes-pvc
minikube

2 Answers

12/20/2021

The local mount you created mounts the specified directory into minikube, but not from the guest to the host as you would like it to.

Depending on your host machine's OS you will have to set up proper file sharing using either host folder sharing or a network based file system.

With a bit of work, one could set up Syncthing between the host and the guest VM for persistent file synchronization.

Grab the latest release of Syncthing for your operating system & unpack it (if you use Debian/Ubuntu you may want to use the Debian repository)

At this point Syncthing will also have set up a folder called Default Folder for you, in a directory called Sync in your home directory (%USERPROFILE% on Windows). You can use this as a starting point, then remove it or add more folders later.

The admin GUI starts automatically and remains available on http://localhost:8384/. Cookies are essential to the correct functioning of the GUI; please ensure your browser accepts them.

On the left is the list of “folders”, or directories to synchronize. You can see the Default Folder was created for you, and it’s currently marked “Unshared” since it’s not yet shared with any other device. On the right is the list of devices. Currently there is only one device: the computer you are running this on.

For Syncthing to be able to synchronize files with another device, it must be told about that device. This is accomplished by exchanging “device IDs”. A device ID is a unique, cryptographically-secure identifier that is generated as part of the key generation the first time you start Syncthing. It is printed in a log, and you can see it in the web GUI by selecting “Actions” (top right) and “Show ID”.

Two devices will only connect and talk to each other if they are both configured with each other’s device ID. Since the configuration must be mutual for a connection to happen, device IDs don’t need to be kept secret. They are essentially part of the public key.

To get your two devices to talk to each other click “Add Remote Device” at the bottom right on both devices, and enter the device ID of the other side. You should also select the folder(s) that you want to share. The device name is optional and purely cosmetic. You can change it later if desired. Once you click “Save” the new device will appear on the right side of the GUI (although disconnected) and then connect to the new device after a minute or so. Remember to repeat this step for the other device.

At this point the two devices share an empty directory. Adding files to the shared directory on either device will synchronize those files to the other side.

What is Syncthing: https://syncthing.net/

Installation Guide: https://docs.syncthing.net/intro/getting-started.html

Lates Release of syncthing: https://github.com/syncthing/syncthing/releases/tag/v1.18.5

Debian Repo: https://apt.syncthing.net/

-- Dan
Source: StackOverflow

12/21/2021

The problem was the Firewall. The procedure detailed within the question post together with the solution proposed in this answer (on Ubuntu) worked for me:

How to mount a Host folder in minikube VM

-- rluq
Source: StackOverflow