我创建了一个简单的本地存储卷。像这样:
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol1
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /srv/volumes/vol1
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- my-node
我提出 claim :
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage:1Gi
由于未知原因,他们没有比赛。我究竟做错了什么?
最佳答案
关于本地存储,值得注意的是:
Using local storage ties your application to that specific node, making your application harder to schedule. If that node or local volume encounters a failure and becomes inaccessible, then that pod also becomes inaccessible. In addition, many cloud providers do not provide extensive data durability guarantees for local storage, so you could lose all your data in certain scenarios.
这是针对Kubernetes 1.10的。在Kubernetes中,1.14本地永久卷成为GA。
您发布了一个要求该用户的答案。只是为了澄清您的用户意思是诸如 pods ,部署,statefullset等的使用者。
因此,仅使用一个简单的pod定义将使您的PV受到约束:
kind: Pod
apiVersion: v1
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: "/var/www/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim
现在,当您删除 pods 并尝试运行另一个 pods 时,就会发生问题。在这种情况下,如果您或其他人愿意寻找解决方案,则此GitHub issue中对此进行了描述。
希望这能清除一切。
关于kubernetes - 永久数量与声明不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55768986/