Kubernetes - PVC不绑定NFS PV

时间:2017-05-22 19:21:28

标签: kubernetes

我使用NFS和PVC为同一卷创建了一个物理卷。但是,PVC始终会创建EBS磁盘存储,而不是绑定到PV。请参阅下面的日志:

> kubectl get pv
NAME      CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM     STORAGECLASS   REASON    AGE
mynfspv   100Gi      RWX           Retain          Available                                      7s

立即创建PVC

> kubectl get pvc
NAME       STATUS    VOLUME                                     CAPACITY   ACCESSMODES   STORAGECLASS   AGE
mynfspvc   Bound     pvc-a081c470-3f23-11e7-9d30-024e42ef6b60   100Gi      RWX           default        4s


> kubectl get pv
NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM              STORAGECLASS   REASON    AGE
mynfspv                                    100Gi      RWX           Retain          Available                                               50s
pvc-a081c470-3f23-11e7-9d30-024e42ef6b60   100Gi      RWX           Delete          Bound       default/mynfspvc   default                  17s

NFS-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mynfspv
  labels:
    name: nfs2
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: dbc56.efs.us-west-2.amazonaws.com
    path: /

NFS-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mynfspvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Gi

2 个答案:

答案 0 :(得分:7)

您似乎启用了动态配置和默认存储类功能,默认类是AWS ebs。您可以使用以下命令检查默认类:

$ kubectl get storageclasses
NAME                 TYPE
standard (default)   kubernetes.io/aws-ebs

如果这是正确的,那么我认为您需要指定存储类来解决您的问题。

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: nfs-class
provisioner: kubernetes.io/fake-nfs

为您的两个PV添加存储类名称

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mynfspvc
spec:
  storageClassName: nfs-class
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Gi

和PVC

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mynfspv
  labels:
    name: nfs2
spec:
  storageClassName: nfs-class
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: dbc56.efs.us-west-2.amazonaws.com
    path: /

您可以查看https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class-1了解详情。

答案 1 :(得分:0)

这是哪个版本的Kube?根本原因如@ddysher所述。在您的设置中,“默认”存储类是“EBS”,您可以在get pv {c}输出中看到。根据kube版本,您还可以使用PVC规格中的“calim selector”。请参阅#https://github.com/kubernetes/community/blob/master/contributors/design-proposals/volume-selectors.md