k8s基础-pv/pvc问题分析 pod has unbound immediate PersistentVolumeClaims

问题描述: 用户反应deployment创建不成功, 通过describe查看报错如下,

pod has unbound immediate PersistentVolumeClaims

用户自己也查了按照网上的方法都没解决。我也按照用户提供方法尝试了一下,没有成功。

从提示看,是pod不能绑定到pvc,我第一感觉是pv,pvc是不是配置有问题。

最后发现确实是管理员pv写的太草率了。重点部分已经标黑,image核心我用nginx替换了。

(weops) [root@node201 pv]# cat pv.yml
apiVersion: v1
kind: PersistentVolume                       #PV类型
metadata:
  name: nfs-pv1
  labels:
    pv: nfs-pv1

spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany                          #ReadWriteOnce表示mount到单个节点; ReadOnlyMany表示PV能以read-only mount到多个节点; ReadWriteMany表示PV能以read-write mount到多个节点
  persistentVolumeReclaimPolicy: Recycle     #Recycle表示清除PV中的数据;Delete表示删除storage provider上的对应资源;Retain表示需要管理员手工回收
  storageClassName: nfs                      #PVC的申请,通过class该项指定
  #claimRef:     #从pv端逆向绑定pvc
  #  kind: PersistentVolumeClaim
  #  namespace: default
  #  name: nfs-pvc1

  nfs:
    path: /nfs/data/pv001
    server: 192.168.56.102

(weops) [root@node201 pv]# cat pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc1
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: nfs           #
  selector:
    matchLabels:
      pv: nfs-pv1

(weops) [root@node201 pv]# cat deployment-with-nfs-pvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-nfs-pvc
  labels:
    app: deployment-nfs-pvc
spec:
  replicas: 2
  selector:
    matchLabels:
      app: deployment-nfs-pvc
  template:
    metadata:
      labels:
        app: deployment-nfs-pvc
    spec:
      containers:
      - name: nfs-pvc-container
        image: nginx
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: nfs-data
          mountPath: "/var/www/html"
      volumes:

      - name: nfs-data
        persistentVolumeClaim:
          claimName: nfs-pvc1

你可能感兴趣的:(k8s开发基础,kubernetes)