我正在努力在 kubernetes 中创建持久卷和持久卷声明。以下配置工作正常,我能够将数据存储在持久卷存储路径中。
我创建了持久卷
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-vol
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi #Size of the volume
accessModes:
- ReadWriteOnce #type of access
hostPath:
path: "/mnt/data" #host location
---
和持久性卷声明:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
这里,上述配置文件中的持久卷和持久卷声明之间没有任何联系。两者如何相互绑定(bind)。
Persistence volume & persistence volume claim
比如说在deployment.yml中,我们可以指向持久卷声明的名称。这样POD -> PVC -> PV -> 主机存储位置。
任何人都可以帮助我了解持久卷和持久卷声明如何通过上述配置文件相互绑定(bind)。
最佳答案
简而言之,PV 和 PVC 之间的绑定(bind)是通过匹配 capacity
和 accessModes
来决定的。由于 PV 和 PVC 中都有 1Gi
和 ReadWriteOnce
,因此绑定(bind)成功。
来自文档 here
A user creates, or in the case of dynamic provisioning, has already created, a PersistentVolumeClaim with a specific amount of storage requested and with certain access modes. A control loop in the master watches for new PVCs, finds a matching PV (if possible), and binds them together. If a PV was dynamically provisioned for a new PVC, the loop will always bind that PV to the PVC. Otherwise, the user will always get at least what they asked for, but the volume may be in excess of what was requested. Once bound, PersistentVolumeClaim binds are exclusive, regardless of how they were bound. A PVC to PV binding is a one-to-one mapping, using a ClaimRef which is a bi-directional binding between the PersistentVolume and the PersistentVolumeClaim.
Claims will remain unbound indefinitely if a matching volume does not exist. Claims will be bound as matching volumes become available. For example, a cluster provisioned with many 50Gi PVs would not match a PVC requesting 100Gi. The PVC can be bound when a 100Gi PV is added to the cluster
关于kubernetes - 持久卷和持久卷声明如何在 kubernetes 中相互绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62977038/