skip to Main Content

Im just starting this trip into cloud native and kubernetes(minikube for now), but im stuck because i cannot pass files and persist into pod containers.
Nginx,php-fpm and mariadb containers. Now, i just need to test app in kubernetes(docker-compose is running ok), that means as i was doing in docker-compose.
How can i mount volumes in this scenario?

Volume file:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /var/lib/docker/volumes/sylius-standard-mysql-sylius-dev-data/_data/sylius

Claim File:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

Thank you for the guidance…

2

Answers


  1. It depends on which Minikube driver you’re using. Check out https://minikube.sigs.k8s.io/docs/handbook/mount/ for a full overview, but basically you have to make sure the host folder is shared with the guest VM, then hostPath volumes will work as normal. You may want to try Docker Desktop instead as it somewhat streamlines this process.

    Login or Signup to reply.
  2. found on minikube github repo: feature request: mount host volumes into docker driver:

    Currently we are mounting the /var directory as a docker volume, so
    that’s the current workaround.

    i.e. use this host directory, for getting things into the container ?

    See e.g. docker volume inspect minikube for the details on it

    So you may want to try to use the /var dir as workaround.


    If the previous solution doesn’t meet your expectations and you still want to use docker as your minikube driver – don’t, because you can’t use extra mounts with docker (as far as I know). Use a VM.

    Other solution: if you don’t like the idea of using a VM, use kind (kuberntes in docker).

    kind supports extra mounts. To configure it, check the kind documentation on extra mounts:

    Extra Mounts
    Extra mounts can be used to pass through storage on the host to a kind node for persisting data, mounting through code etc.

    kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes:
    - role: control-plane   # add a mount from /path/to/my/files on the host to /files on the node   
      extraMounts:
      - hostPath: /path/to/my/files/
        containerPath: /files
    

    And the rest is like you described: You need to create a PV with the same hostPath as specified by containerPath.


    You could also use minikube without any driver by specifying --driver=none with minikube start, which can be usefull in some cases, but check the minikube docs for more information.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search