Search code examples
mongodbkubernetespersistent-volumes

Kubernetes persistent volumes smaller than requested


On attempt to deploy MongoDB to a Kubernetes cluster with MongoDB Kubernetes Operator, I am seeing the following error in persistent volumes:

$ kubectl describe pvc data-volume-mongodb-0
(...)
  Warning  ProvisioningFailed    31s (x4 over 2m45s)   (...).com_csi-controller-0_b0e3662f-4b9e-4de5-a45b-0132ab5971a8  failed to provision volume with StorageClass "tier1": created volume capacity 9663676416 less than requested capacity 10000000000.(...)

Is this an issue with my provider or a known Kubernetes issue?


Solution

  • MongoDB Kubernetes Operator default data volume capacity is 10G.

    I was able to override it with my own PVC:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: data-volume-kompas2mongo-0
      labels:
        app: kompas2mongo-svc
    spec:
      storageClassName: tier1
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
    

    Deployed to my clusted with:

    $ kubectl apply -f mongodb-data-pvc.yaml
    

    I did the same for the logs volume:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: logs-volume-kompas2mongo-0
      labels:
        app: kompas2mongo-svc
    spec:
      storageClassName: tier1
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
    

    Deployed to my clusted with:

    $ kubectl apply -f mongodb-logs-pvc.yaml
    

    Changing 10G to 10Gi, and 2G to 2Gi did the trick for me. After that, both volumes got provisioned correctly:

    $ kubectl get pv
    NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                STORAGECLASS   REASON   AGE
    pvc-df6b01e9-af96-470d-af37-49c6993b70e6   10Gi       RWO            Delete           Bound    default/data-volume-kompas2mongo-0   tier1                   3h8m
    pvc-f2f08105-61c4-444c-b7e0-900aa403c122   2Gi        RWO            Delete           Bound    default/logs-volume-kompas2mongo-0   tier1                   3h8m