最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Kubernetes: RWO PVC bound to two pods on different nodes seems to use two PV? - Stack Overflow

programmeradmin0浏览0评论

I applied the following configuration with

  • one RWO PV
  • one RWO PVC
  • two pods both using the above PVC.
apiVersion: v1
kind: PersistentVolume
metadata:
  name: vol1
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: claim1
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
---
apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
    - name: myfrontend
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: data
      resources:
        limits:
          cpu: "1"
          memory: "200Mi"
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: claim1
---
apiVersion: v1
kind: Pod
metadata:
  name: pod2
spec:
  containers:
    - name: myfrontend
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: data
      resources:
        limits:
          cpu: "1"
          memory: "200Mi"
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: claim1

The pods got scheduled onto two different nodes and, according to GitHub issues #103305 and #26567, I was expecting one of the two pods to fail (i.e. not reaching Running state) because of the RWO constraint.

However, both pods reached Running state and I found that the pods were even able to write to the PVC.

After having deleted all resources, I checked the two nodes and I found the data written by the pods. Actually, it seems that two different RWO PV were created and used.

Naturally, Kubernetes was showing just the PV and the PVC that were defined in the configuration.

How did Kubernetes managed this situation?

I've also tried not to define the PV and let the cluster provision it. I made two experiments:

  1. I defined the PVC and pod1, applied the configuration, and then created pod2. The results didn't change: both pods were able to run and use the PVC.

  2. I defined and applied PVC and both pods in one configuration. In this case, both pods (scheduled on different nodes) stuck at ContainerCreating while volume attachment was failing in loop.

Even though the second experiment outcome seems correct, I cannot find out why the first experiment went differently, since I just delayed the definition of pod2.

发布评论

评论列表(0)

  1. 暂无评论