Kubernetes PersistentVolume 和 PersistentVolumeClaim 可能导致我的 pod 出现问题,在复制日志时崩溃
Kubernetes PersistentVolume and PersistentVolumeClaim could be causing issues for my pod which crashes while copying logs
我有一个 PersistentVolume,我指定如下:
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv-shared
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 5Gi
hostPath:
path: /data/mypv-shared/
然后我创建了一个具有以下规范的 PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypv-shared-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
但是当我创建 PVC 时,运行ning kubectl get pv
显示它绑定到随机生成的 PV
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-38c77920-a223-11e7-89cc-08002719b642 5Gi RWX Delete Bound default/mypv-shared standard 16m
我认为这会在 运行ning 测试时导致我的 pods 出现问题,因为我不确定 pod 是否正确安装指定目录。我的 pods 在尝试复制 运行 结束时的测试日志时在测试结束时崩溃。
真正的原因是 persistentVolume/Claim 还是我应该调查其他问题?谢谢!
创建 PVC 动态供应 PV,而不是使用您通过 hostpath
手动创建的 PV。在 PVC 上简单地设置 .spec.storageClassName
和一个空字符串 (""
)
A PVC with its storageClassName set equal to ""
is always interpreted to be requesting a PV with no class, so it can only be bound to PVs with no class (no annotation or one set equal to ""). A PVC with no storageClassName is not quite the same ...
所以创建这样的东西(我还添加了标签和选择器以确保预期的 PV 与 PVC 配对;您可能不需要该约束):
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv-shared
labels:
name: mypv-shared
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 5Gi
hostPath:
path: /data/mypv-shared/
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypv-shared-claim
spec:
storageClassName: ""
selector:
matchLabels:
name: mypv-shared
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
我有一个 PersistentVolume,我指定如下:
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv-shared
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 5Gi
hostPath:
path: /data/mypv-shared/
然后我创建了一个具有以下规范的 PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypv-shared-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
但是当我创建 PVC 时,运行ning kubectl get pv
显示它绑定到随机生成的 PV
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-38c77920-a223-11e7-89cc-08002719b642 5Gi RWX Delete Bound default/mypv-shared standard 16m
我认为这会在 运行ning 测试时导致我的 pods 出现问题,因为我不确定 pod 是否正确安装指定目录。我的 pods 在尝试复制 运行 结束时的测试日志时在测试结束时崩溃。
真正的原因是 persistentVolume/Claim 还是我应该调查其他问题?谢谢!
创建 PVC 动态供应 PV,而不是使用您通过 hostpath
手动创建的 PV。在 PVC 上简单地设置 .spec.storageClassName
和一个空字符串 (""
)
A PVC with its storageClassName set equal to
""
is always interpreted to be requesting a PV with no class, so it can only be bound to PVs with no class (no annotation or one set equal to ""). A PVC with no storageClassName is not quite the same ...
所以创建这样的东西(我还添加了标签和选择器以确保预期的 PV 与 PVC 配对;您可能不需要该约束):
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv-shared
labels:
name: mypv-shared
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 5Gi
hostPath:
path: /data/mypv-shared/
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypv-shared-claim
spec:
storageClassName: ""
selector:
matchLabels:
name: mypv-shared
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi