25

Is there any way to share the directory/files to kubernetes container from your local system?

I have a deployment yaml file. I want to share the directory without using kubectl cp.

I tried with configmap but I later came to know that configmap can not have the whole directory but only a single file.

If anyone has any idea please share.

Please note: I do not want to host the file into minikube but I want to push the directory directly to container

Akshay Sood
  • 6,366
  • 10
  • 36
  • 59
  • You can create a PV and store the files there, accessing them in your cluster by mounting it as a volume in your pods. You can see the list of options [here](https://kubernetes.io/docs/concepts/storage/storage-classes/). Where is your cluster hosted? – Yaniv Oliver Aug 27 '18 at 11:15
  • @yanivoliver I am using minikube local system – Akshay Sood Aug 27 '18 at 11:21
  • Possible duplicate of [Mount local directory into pod in minikube](https://stackoverflow.com/questions/48534980/mount-local-directory-into-pod-in-minikube) – Crou Aug 27 '18 at 11:26
  • You can use the [CIFS Flexvolume Plugin for Kubernetes](https://github.com/fstab/cifs). It will allow you to access a CIFS (SMB) network share – Yaniv Oliver Aug 27 '18 at 11:26

1 Answers1

33

I found a way.

We can specify the directory we want to add into container by using hostPath in volumes

      volumeMounts:
        - name: crypto-config
          mountPath: <PATH IN CONTAINER>
        - name: channel-artifacts
          mountPath: /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
        - name: chaincode
          mountPath: /opt/gopath/src/github.com/chaincode
  volumes:
    - name: crypto-config
      hostPath:
        path: <YOUR LOCAL DIR PATH>
    - name: channel-artifacts
      hostPath:
        path: /Users/akshaysood/Blockchain/Kubernetes/Fabric/network/channel-artifacts
    - name: chaincode
      hostPath:
        path: /Users/akshaysood/Blockchain/Kubernetes/Fabric/network/chaincode
Akshay Sood
  • 6,366
  • 10
  • 36
  • 59
  • 3
    For the local dir Path, it is possible to use Relative Path ? – lupaulus Feb 04 '21 at 20:11
  • 1
    based on kubernetes documentation, this present a security risk: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath – Marko Jan 12 '22 at 21:16