Answers: <p>Try running the command kubectl get pvc mongo-volume-claim.
  This should give you a log message telling you why it is pending.</p>
  <p>Looking at your provisioned it looks like you are using GKE to spin this cluster up. Did you provision the storage already?
  Im not too familiar with GKE but i use AWS EKS for my clusters..When using AWS you also have to ensure that the storage add-on has been enabled for the cluster..</p>
  <p>So I would ensure that you provisioned the storage for this cluster.
  Check the logs.
  Make sure you</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-07-28T23:28:18.180Z
Answers: 2023-07-28T23:28:18.180Z
Answers: Freddy
Answers: <p>You need to create in your mongo-storage.yaml the resource &quot;PersistentVolume&quot; and set too the storageClassName, and persistentVolumeReclaimPolicy to RETAIN like following.</p>
  <pre><code>apiVersion: v1 
  kind: PersistentVolume
  metadata:
    name: mongo-volume-pv
  spec:
    storageClassName: slow
    capacity:
      storage: 3Gi
    accessModes:
      - ReadWriteOnce
    persistentVolumeReclaimPolicy: Retain 
    hostPath:
      path: &quot;/mnt/data&quot;
      type: DirectoryOrCreate
  </code></pre>
  <p>The PersistentVolumeClaim does a call to StorageClass that looks for a PersistentVolume idle.
  Don't forget to include in your storageclass the line <em><strong>volumeBindingMode: WaitForFirstConsumer</strong></em>
  Now, if you restart your pod, the kubernetes will persist your data.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-07-26T20:32:47.537Z
Answers: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Answers: Community
Answers: CC BY-SA 4.0
Answers: 2023-07-26T18:11:43.683Z
Answers: 2023-07-27T00:59:13.837Z
Answers: 2023-07-27T00:59:13.837Z
Answers: Cléber Cavlcanti
Body: <p>Minimum reproducible example:</p>
  <pre class="lang-yaml prettyprint-override"><code># mongo-storage.yaml
  ---
  apiVersion: storage.k8s.io/v1
  kind: StorageClass
  metadata:
    name: slow
  provisioner: kubernetes.io/gce-pd
  parameters:
    type: pd-standard
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: mongo-volume-claim
  spec:
    storageClassName: &quot;slow&quot;
    accessModes:
      - ReadWriteOnce 
    resources:
      requests:
        storage: 512Mi
  </code></pre>
  <p>Given the above yaml, when created with <code>kubectl apply -f mongo-storage.yaml</code>, the PVC remains pending given minutes to create.</p>
  <p>When <code>kubectl get -f mongo-storage.yaml</code> is run, the below is returned.</p>
  <pre><code>NAME                               PROVISIONER            RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
  storageclass.storage.k8s.io/slow   kubernetes.io/gce-pd   Delete          Immediate           false                  58s
  
  NAME                                       STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
  persistentvolumeclaim/mongo-volume-claim   Pending                                      slow           58s
  </code></pre>
  <p>I didn't have a storageclass at all, but I found <a href="https://stackoverflow.com/questions/44891319/kubernetes-persistent-volume-claim-indefinitely-in-pending-state">this thread</a> troubleshooting. The storageclass is copy pasted from <a href="https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/" rel="nofollow noreferrer">the docs</a> for dynamic storage provisioning.</p>
  <p>I'm just trying to make my DB persist past restarts. I've pasted the whole yaml at <a href="https://pastebin.com/BSFEB5Dp" rel="nofollow noreferrer">https://pastebin.com/BSFEB5Dp</a>, let me know if there's any other ways to have this persistent storage. This is mostly scrapped together from various google searches, I can't pretend to fully understand every config option here.</p>
  <p>I'm extremely new to Kubernetes, please let me know if there's anything I'm missing, or any way I could improve my question.</p>
  
Tags: <kubernetes><kubernetes-volume>
Title: Persistant storage claim stuck on pending with local storage in minikube, even with a storage class provided
UserDisplayName: zleyyij
ThreadText: # Persistant storage claim stuck on pending with local storage in minikube, even with a storage class provided
  
  (Asked by: username_0 on 2023-07-24)
  
  Minimum reproducible example:
  
  ```yaml
  # mongo-storage.yaml
  ---
  apiVersion: storage.k8s.io/v1
  kind: StorageClass
  metadata:
    name: slow
  provisioner: kubernetes.io/gce-pd
  parameters:
    type: pd-standard
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: mongo-volume-claim
  spec:
    storageClassName: "slow"
    accessModes:
      - ReadWriteOnce 
    resources:
      requests:
        storage: 512Mi
  
  ```
  
  Given the above yaml, when created with `kubectl apply -f mongo-storage.yaml`, the PVC remains pending given minutes to create.
  
  When `kubectl get -f mongo-storage.yaml` is run, the below is returned.
  
  ```
  NAME                               PROVISIONER            RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
  storageclass.storage.k8s.io/slow   kubernetes.io/gce-pd   Delete          Immediate           false                  58s
  
  NAME                                       STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
  persistentvolumeclaim/mongo-volume-claim   Pending                                      slow           58s
  
  ```
  
  I didn't have a storageclass at all, but I found [this thread](https://stackoverflow.com/questions/44891319/kubernetes-persistent-volume-claim-indefinitely-in-pending-state) troubleshooting. The storageclass is copy pasted from [the docs](https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/) for dynamic storage provisioning.
  
  I'm just trying to make my DB persist past restarts. I've pasted the whole yaml at <https://pastebin.com/BSFEB5Dp>, let me know if there's any other ways to have this persistent storage. This is mostly scrapped together from various google searches, I can't pretend to fully understand every config option here.
  
  I'm extremely new to Kubernetes, please let me know if there's anything I'm missing, or any way I could improve my question.
  
  **Tags:** kubernetes, kubernetes-volume
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-07-28. Score: 0
  
  Try running the command kubectl get pvc mongo-volume-claim.
  This should give you a log message telling you why it is pending.
  
  Looking at your provisioned it looks like you are using GKE to spin this cluster up. Did you provision the storage already?
  Im not too familiar with GKE but i use AWS EKS for my clusters..When using AWS you also have to ensure that the storage add-on has been enabled for the cluster..
  
  So I would ensure that you provisioned the storage for this cluster.
  Check the logs.
  Make sure you
  
  
  ---
  
  ### Answer by username_2 on 2023-07-26. Score: 0
  
  You need to create in your mongo-storage.yaml the resource "PersistentVolume" and set too the storageClassName, and persistentVolumeReclaimPolicy to RETAIN like following.
  
  ```
  apiVersion: v1 
  kind: PersistentVolume
  metadata:
    name: mongo-volume-pv
  spec:
    storageClassName: slow
    capacity:
      storage: 3Gi
    accessModes:
      - ReadWriteOnce
    persistentVolumeReclaimPolicy: Retain 
    hostPath:
      path: "/mnt/data"
      type: DirectoryOrCreate
  
  ```
  
  The PersistentVolumeClaim does a call to StorageClass that looks for a PersistentVolume idle.
  Don't forget to include in your storageclass the line ***volumeBindingMode: WaitForFirstConsumer***
  Now, if you restart your pod, the kubernetes will persist your data.
  
  > **Comments:**
  > **username_3**: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).  
  
  ---
  
  