kubernetes - 永久数量与声明不匹配

标签 kubernetes persistent-volumes persistent-volume-claims

我创建了一个简单的本地存储卷。像这样:

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/

相关文章:

Kubernetes,无法通过 DNS 挂载 NFS 共享

mysql - 如何使用本地挂载的数据卷创建 mysql kubernetes 服务?

postgresql - 为另一个 PersistentVolumeClaim 重用持久卷

kubernetes - 如何像 kubernetes 文档中那样 curl 服务?

Azure Kubernetes (AKS) 不释放公共(public) IP

kubectl - Kubernetes pods 看不到带有kubectl的 secret 集吗?

kubernetes - Portworx 到 ETCD 的连接不起作用(http 与 https)

docker - 如何从minikube访问Rabbitmq的管理UI?

docker - Kubernetes 上 Jenkins 的持久卷

kubernetes - 为 Kubernetes Deployment 中的每个副本绑定(bind)不同的 Persistent Volume