One of two PersistentVolumeClaims' status is "Pending"

4/11/2019

I have a file has PV, Service and 2 Pod statefulset including Dynamic PVC. When I deployed the file, a problem happened at PVC status.

# kubectl get pvc
NAME            STATUS    VOLUME           CAPACITY   ACCESS MODES   STORAGECLASS       AGE
www-web-0       Bound     pv-test          10Gi       RWO            my-storage-class   7m19s
www-web-1       Pending                                              my-storage-class   7m17s

One of PVC's Status is "Pending" and the reason is "Storage class name not found". But one of PVC was created normally.

Below is the content of the file.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-test
  labels:
    type: local
spec:
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: "my-storage-class"
  capacity:
    storage: 10Gi
  hostPath:
    path: /tmp/data
    type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 2 # by default is 1
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

If someone knows the cause, let me know. Thanks in advance.

Describe information about PV, PVC (www-web-1), Pod (web-1)

kubectl describe pv pv-test
Name:            pv-test
Labels:          type=local
Annotations:     kubectl.kubernetes.io/last-applied-configuration:
                   {"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"labels":{"type":"local"},"name":"pv-test"},"spec":{"accessModes...
                 pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    my-storage-class
Status:          Bound
Claim:           default/www-web-0
Reclaim Policy:  Delete
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   <none>
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /tmp/data
    HostPathType:  DirectoryOrCreate
Events:            <none>

#kubectl  describe pvc www-web-1
Name:          www-web-1
Namespace:     default
StorageClass:  my-storage-class
Status:        Pending
Volume:
Labels:        app=nginx
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Events:
  Type       Reason              Age               From                         Message
  ----       ------              ----              ----                         -------
  Warning    ProvisioningFailed  20s (x7 over 2m)  persistentvolume-controller  storageclass.storage.k8s.io "my-storage-class" not found
Mounted By:  web-1


#kubectl describe po web-1
Name:               web-1
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               <none>
Labels:             app=nginx
                    controller-revision-hash=web-6596ffb49b
                    statefulset.kubernetes.io/pod-name=web-1
Annotations:        <none>
Status:             Pending
IP:
Controlled By:      StatefulSet/web
Containers:
  nginx:
    Image:        k8s.gcr.io/nginx-slim:0.8
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:
      /usr/share/nginx/html from www (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lnfvq (ro)
Conditions:
  Type           Status
  PodScheduled   False
Volumes:
  www:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  www-web-1
    ReadOnly:   false
  default-token-lnfvq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-lnfvq
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason            Age                      From               Message
  ----     ------            ----                     ----               -------
  Warning  FailedScheduling  3m43s (x183 over 8m46s)  default-scheduler  pod has unbound immediate PersistentVolumeClaims (repeated 3 times)
-- aspirant75
kubernetes
kubernetes-pvc

2 Answers

4/11/2019

You are using hostpath volume to store the data. You are using /tmp/data on the host. Ensure that /tmp/data directory exists in all the nodes in the cluster.

-- P Ekambaram
Source: StackOverflow

4/11/2019

Your volume pv-test has accessModes: - ReadWriteOnce I think you need to create one more volume for second pod.

So I think if www-web-1 is also trying to mount pv-test it won't be able to mount it.

-- Ankit Deshpande
Source: StackOverflow