0

Minimum reproducible example:

# 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 troubleshooting. The storageclass is copy pasted from the docs 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.

2 Answers 2

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.

1
  • 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.
    – Community Bot
    Jul 26, 2023 at 20:32
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.