Persistence claim is stuck in pending

671 Views Asked by At

I am installing a chart using helm but its Pod and PVC are getting stuck in pending state but I see PV are in available state.

I face this issue intermittently while installing chart

Pod describe :

Events:
  Type     Reason            Age                 From               Message
  ----     ------            ----                ----               -------
  Warning  FailedScheduling  0s (x4 over 2m17s)  default-scheduler  0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.

PVC describe :

Name:          web-claim0
Namespace:     edge
StorageClass:  edge-custom
Status:        Pending
Volume:
Labels:        app.kubernetes.io/managed-by=Helm
               io.kompose.service=web-claim0
Annotations:   meta.helm.sh/release-name: manifest
               meta.helm.sh/release-namespace: edge
               volume.beta.kubernetes.io/storage-provisioner: docker.io/hostpath
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Used By:       web-69bd64d5cf-lmnqd
Events:
  Type    Reason                Age                  From                         Message
  ----    ------                ----                 ----                         -------
  Normal  ExternalProvisioning  6s (x17 over 3m54s)  persistentvolume-controller  waiting for a volume to be created, either by external provisioner "docker.io/hostpath" or manually created by system administrator

I have storage class as

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: {{ .Values.prefix }}-custom
provisioner: docker.io/hostpath
reclaimPolicy: Retain
volumeBindingMode: Immediate

PVC.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: web-claim0
  name: web-claim0
spec:
  storageClassName: {{ .Values.prefix }}-custom
  selector:
    matchLabels:
      for_app: {{ .Values.prefix }}-manifest-web
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
status: {}

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ .Values.prefix }}-manifest-web-pv
  labels:
    for_app: {{ .Values.prefix }}-manifest-web
    type: local
spec:
  persistentVolumeReclaimPolicy: Retain
  storageClassName: {{ .Values.prefix }}-custom
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/{{ .Values.prefix }}-manifeststorage"

on other hand PV is in available state

2

There are 2 best solutions below

0
On

I had two pv,pvc with same app name due to which first pvc was getting bounded to pv which was create to other pvc. when kept unique app name specific to pv and pvc issue was resolved

0
On

Seems like PVC is unable to bind the PV. What you can do is you can add one claimRef block inside PV.

Something like this under the spec of pv:

claimRef:
  apiVersion: v1
  kind: PersistentVolumeClaim
  name: your pvc name that you will create after creating PV
  namespace: your namespace name

Now you need to create the pvc with the name you mentioned previously inside the mentioned namespace. It will bind as soon as you create the pvc.