Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes share a directory from your local system to kubernetes container

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

like image 698
Akshay Sood Avatar asked Aug 27 '18 11:08

Akshay Sood


People also ask

Do containers in same pod share localhost?

Every container in a Pod shares the network namespace, including the IP address and network ports. Inside a Pod (and only then), the containers that belong to the Pod can communicate with one another using localhost .


1 Answers

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
like image 167
Akshay Sood Avatar answered Sep 24 '22 02:09

Akshay Sood