Running MongoDB on Kubernetes Minikube with local persistent storage Running MongoDB on Kubernetes Minikube with local persistent storage mongodb mongodb

Running MongoDB on Kubernetes Minikube with local persistent storage


TL; DR

In the situation described in the question the problem was that the Pods for the StatefulSet did not start up at all therefore the Service had no targets. The reason for not starting up was:

WarningFailedCreate pvc: myclaim-mongo-0, error: PersistentVolumeClaim "myclaim-mongo-0" is invalid: [spec.accessModes: Required value: at least 1 access mode is required, spec.resources[storage]: Required value]`

And since the volume by default is defined as required the Pod won't start without it. So edit the StatefulSet's volumeClaimTemplate to have:

volumeClaimTemplates:- metadata:    name: myclaim  spec:    accessModes: [ "ReadWriteOnce" ]    resources:      requests:        storage: 1Gi

(There is no need to create the PersistentVolumeClaim manually.)

More general solution

If can't connect a Service try this command:

kubectl describe service myservicename

And if you see something like this in the output:

Endpoints:      <none>

That means there are no targets (usually Pods) running or the targets are not ready. To find out which one is the case do:

kubectl describe endpoint myservicename

It will list all endpoints, ready or not. If not ready, investigate the readinessProbe in the Pod. If doesn't exist then try to find out why by looking at the StatefulSet (Deployment, ReplicaSet, ReplicationController, etc) itself for messages (the Events section):

kubectl describe statefulset mystatefulsetname

This information is available if you do:

kubectl get ev | grep something

If you are sure they are running and ready then the labels on the Pods and the Service do not match up.