Kubernetes将本地系统中的目录共享到kubernetes容器

时间:2018-08-27 11:08:03

标签: kubernetes kubectl minikube

有什么方法可以从本地系统将目录/文件共享到kubernetes容器?

我有一个部署yaml文件。我想不使用kubectl cp来共享目录。

我尝试使用configmap,但后来我知道configmap不能具有整个目录,而只能具有一个文件。

如果有人有任何想法,请分享。

请注意:我不想将文件托管到minikube中,但我想将目录直接推送到容器中

1 个答案:

答案 0 :(得分:7)

我找到了方法。

我们可以使用hostPath中的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