Sharing a persistent volume between pods in Kubernetes

╄→尐↘猪︶ㄣ 提交于 2019-12-10 15:58:01

问题


We have two pods in Kubernetes that for sake of conversation we'll call pod1 and pod2. I created pv1 and pvc1 on pod 1 and it's working fine. In my opinion the documentation is not clear enough about this scenario or I couldn't find the right wiki. How can I access pv1 and pc1 from pod2?


回答1:


From the k8s documentation:

A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.

A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., can be mounted once read/write or many times read-only).

Meaning that in the scenario pictured in the question, if PodA_deployment.yaml creates a volume claim:

volumeMounts:
- name: myapp-data-pv-1
  mountPath: /home/myappdata/mystuff

then PodB will be able to mount the pv making a claim like the following:

volumes:
   - name: myapp-data-pv-1
     persistentVolumeClaim:
       claimName: myapp-data-pvc-1

in PodB_deployment.yaml. While it's clear once and it makes sense once you get to understand it, the documentation could explain it better.



来源:https://stackoverflow.com/questions/46100922/sharing-a-persistent-volume-between-pods-in-kubernetes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!