kubernetes - 持久卷和持久卷声明如何在 kubernetes 中相互绑定(bind)

标签 kubernetes kubernetes-pod

我正在努力在 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)是通过匹配 capacityaccessModes 来决定的。由于 PV 和 PVC 中都有 1GiReadWriteOnce,因此绑定(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/

相关文章:

logging - 如何将 kubernetes 中所有 pod 的日志存储在 Node 上的一处?

kubernetes - 我们可以在 Pod 中为多个容器使用单个卷挂载吗?

kubernetes - 在kubernetes中,如何访问configmap中的环境变量?

kubernetes - 如何使用 Google Compute Engine Instances 设置 Tensorflow 集群来训练模型?

kubernetes - Terraform:错误:Kubernetes 集群无法访问:配置无效

docker - 如何实现Kubernetes POD到POD的通信?

kubernetes - Minikube 未在 Ubuntu 上启动,引发错误

kubernetes - 如何使用 client-go API 返回的 Pod 条件数组?

kubernetes - kubernetes中的Label和Selector有什么区别?

kubernetes - 从服务帐户对受 Google IAP 保护的资源的编程访问被拒绝,并出现无效签名错误