[Mender on Kubernetes] Error connect to db: failed to open mgo session: no reachable servers

Hello,

First and the foremost, I am a kubernetes and mender beginner.

I am trying to run Mender server on kubernetes (not production grade for now) and kops with cluster running on AWS.

Kompose did not work out well for me, so I wrote the .yaml files myself.

My mender-mongo service+deployment file looks like this:

 apiVersion: apps/v1
kind: Deployment
metadata:
  name: mender-mongo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      mender-mongo: web
  template:
    metadata:
      labels:
        mender-mongo: web
    spec:
      containers:
      - name:  mender-mongo
        image: mongo:3.4
        volumeMounts:
          - name: mender-db
            mountPath: "/data/db"
            readOnly: false
        ports:
        - containerPort: 27017
          hostPort: 27017
      volumes:
        # !!! not persistent storage - data will disappear after pod restart !!!
        - name: mender-db
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: mender-mongo
  namespace: default
spec:
  ports:
  - port: 27017
    protocol: TCP
    targetPort: 27017
  selector:
    mender-mongo: web

The 4 containers mender-inventory, mender-device-auth, mender-deployments and mender-useradm are in CrashLoopBackOff state, and the error in each container is same:

failed to connect to db: failed to open mgo session: no reachable servers

Means, these containers cannot access the mongo-server even though they are in the same cluster.

Please help me figure out what is going wrong. If someone has mender server running on kubernetes, kindly share the files if possible. Thanks!