<p>I'm trying to deploy MongoDB 4.2 into Kubernetes without using their Enterprise Operator using <a href="https://medium.com/devgorilla/how-to-deploy-mongodb-on-google-kubernetes-engine-gke-b099862fadbd" rel="nofollow noreferrer">https://medium.com/devgorilla/how-to-deploy-mongodb-on-google-kubernetes-engine-gke-b099862fadbd</a> and it seems to work fine except there is no Primary Replica Set Member. </p>

<p>I think so because all 3 members have type REPLICA_SET_GHOST. Here is example of an error when I try to insert something into db:</p>

<pre><code>Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[
        {address=mongo-0.mongo: 27017, type=REPLICA_SET_GHOST, roundTripTime=0.8 ms, state=CONNECTED
        },
        {address=mongo-1.mongo: 27017, type=REPLICA_SET_GHOST, roundTripTime=0.9 ms, state=CONNECTED
        },
        {address=mongo-2.mongo: 27017, type=REPLICA_SET_GHOST, roundTripTime=0.9 ms, state=CONNECTED
        }
    ];
</code></pre>

<pre><code>apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: mongo
spec:
  serviceName: "mongo"
  replicas: 3
  template:
    metadata:
      labels:
        role: mongo
        environment: test
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: mongo
          image: mongo
          command:
            - mongod
            - "--replSet"
            - rs0
            - "--bind_ip_all"
          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: "nfs-rw"
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 10Gi
</code></pre>

<p>Is there any possibility of configuration property for mongod to ensure that Primary always present?</p>

tillias
<p>I never used this sidecar - I manually setup replica, but I guess you are missing <code>KUBERNETES_MONGO_SERVICE_NAME</code> to use stable network IDs as mentioned in <a href="https://github.com/cvallance/mongo-k8s-sidecar#how-to-use-it" rel="nofollow noreferrer">sidecar repository</a></p>
