<p>I am trying to set <code>PersistentVolumeClaims</code> to my pods. Now the problem is when the <code>deployment</code> is success, the pods are in <code>pending</code> state. When I try to describe the pods, I get the error why they are not spinning up as below:</p>
<blockquote>
<p>Warning  FailedScheduling  20s (x3 over 22s)  default-scheduler  0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 pod has unbound immediate PersistentVolumeClaims.</p>
</blockquote>
<p>This is the <code>yaml</code> for creating the persistent volume and refer it in the deployments</p>
<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
    name: my-pvc
    namespace: mongo  
spec:
    accessModes:
      - ReadWriteOnce
    resources:
        requests:
            storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  namespace: mongo  
  labels:
    name: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels: 
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: mongo
        ports:
        -  containerPort: 27017
        env: 
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-username
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-password
        volumeMounts:
        - name: data  
          mountPath: /data/db
      volumes: 
        - name: data
          persistentVolumeClaim: 
            claimName: my-pvc    
                                  
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  namespace: mongo  
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
      - name: mongo-express
        image: mongo-express
        ports:
        - containerPort: 8081
        env:
        - name: ME_CONFIG_MONGODB_SERVER
          valueFrom:
            configMapKeyRef:
              name: mongodb-url
              key: database_url
        - name: ME_CONFIG_MONGODB_ADMINUSERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-username
        - name: ME_CONFIG_MONGODB_ADMINPASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-password
        volumeMounts:
        - name: data  
          mountPath: /data
      volumes: 
        - name: data
          persistentVolumeClaim: 
            claimName: my-pvc    
---
.
.
.
</code></pre>
<p>I have removed the other yaml configurations from the above and keep the necessary ones only for easy-reading.</p>
<p>and when I try to see the status of the pvc using <code>kubectl get pvc -n mongo</code> I get the below <code>pending</code> status</p>
<blockquote>
<p>my-pvc   Pending                                                     9m54s</p>
</blockquote>
<p>Can someone tell me where I am doing wrong?</p>

<p>As described in <a href="https://stackoverflow.com/a/52669115/213269">answer to pod has unbound PersistentVolumeClaims</a>, if you use a <code>PersistentVolumeClaim</code> you typically need a <em>volume provisioner</em> for Dynamic Volume Provisioning. The bigger cloud providers typically has this, and also Minikube has one that can be enabled.</p>
<p>Unless you have a <em>volume provisioner</em> in your cluster, you need to create a <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">PersistentVolume</a> resource and possibly also a StorageClass and declare how to use your storage system.</p>
<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">Configure a Pod to Use a PersistentVolume for Storage</a> describes how to create a <code>PersistentVolume</code> with a <code>hostPath</code> that may be good for learning or development, but is typically not used in production by applications.</p>
