K8s pod has unbound immediate PersistentVolumeClaims - mongoDB

12/27/2019

I'm trying to deploy mongoDB in my Kubernetes cluster (Google Cloud Platform). Right now I'm focused on minikube local version of the deployment. The thing is that I'm getting error like so: pod has unbound immediate PersistentVolumeClaims

This is my config files which sets up mongodb inside the minikube:

Service file:

apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    name: mongo
spec:
  ports:
    - port: 27017
      targetPort: 27017
  clusterIP: None
  selector:
    role: mongo

Stateful set file:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
spec:
  selector:
    matchLabels:
      role: mongo
  serviceName: "mongo"
  replicas: 1
  template:
    metadata:
      labels:
        role: mongo
        environment: test
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: mongo
          image: mongo
          command:
            - mongod
            - "--replSet"
            - rs0
            - "--smallfiles"
            - "--noprealloc"
          ports:
            - containerPort: 27017
          volumeMounts:
            - name: mongo-persistent-storage
              mountPath: /data/db
        - name: mongo-sidecar
          image: cvallance/mongo-k8s-sidecar
          env:
            - name: MONGO_SIDECAR_POD_LABELS
              value: "role=mongo,environment=test"
  volumeClaimTemplates:
    - metadata:
        name: mongo-persistent-storage
        annotations:
          volume.beta.kubernetes.io/storage-class: "fast"
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 2Gi

Storage class file:

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: fast
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd

What am I missing here?

-- Murakami
kubernetes
mongodb

2 Answers

12/30/2019

I work with minikube during the feature development and I am running MongoDB as well, I would recommend you to use the hostPath when working with minikube, here is my volume definition:

volume

apiVersion: "v1"
kind: "PersistentVolume"
metadata:
  name: "blog-repoflow-resources-data-volume"
  namespace: repoflow-blog-namespace
  labels:
    service: "resources-data-service"
    fsOwner: "1001"
    fsGroup: "0"
    fsMode: "775"
spec:
  capacity:
    storage: "500Mi"
  accessModes:
    - "ReadWriteOnce"
  storageClassName: local-storage
  hostPath:
    path: /home/docker/production/blog.repoflow.com/volumes/blog-repoflow-resources-data-volume

The complete cluster is up and running and open source: repository.

Check also the stateful, volume claim and service definitions

-- Victor Jimenez
Source: StackOverflow

12/27/2019

I think the problem is that you are trying to apply of

provisioner: kubernetes.io/gce-pd

this should not work locally, as it is intended for GCE PD.

For minikube, you can create hostPath pvc. Read more

-- Arslanbekov
Source: StackOverflow