<p>I've been running a community version of the MongoDB replica set in Kubernetes for over a year now. For reference, I am deploying with these Helm charts:
<a href="https://github.com/mongodb/helm-charts/tree/main/charts/community-operator" rel="nofollow noreferrer">https://github.com/mongodb/helm-charts/tree/main/charts/community-operator</a>
<a href="https://github.com/mongodb/helm-charts/tree/main/charts/community-operator-crds" rel="nofollow noreferrer">https://github.com/mongodb/helm-charts/tree/main/charts/community-operator-crds</a></p>
<p>I now have a need to spin up a couple extra replica sets. I cannot reuse the existing rs because this new deployment is software from one of our subcontractors and we want to keep it separate. When I try to start a new rs, all the rs on the namespace get into a bad state, failing readiness probes.</p>
<p>Do the different replica sets each require their own operator? In an attempt to test that theory, I modified the values.yaml and deployed an operator for each rs but I'm still getting the error.</p>
<p>I think I am missing a config on the DB deployment that tells it which operator to use, but I can't find that config option in the helm chart (referencing the 2nd link from earlier <a href="https://github.com/mongodb/helm-charts/blob/main/charts/community-operator-crds/templates/mongodbcommunity.mongodb.com_mongodbcommunity.yaml" rel="nofollow noreferrer">https://github.com/mongodb/helm-charts/blob/main/charts/community-operator-crds/templates/mongodbcommunity.mongodb.com_mongodbcommunity.yaml</a>)</p>
<p><strong>EDIT:</strong> For a little extra info, it seems like the mongodb can be used without issue. Kubernetes is just showing an error, saying the readiness probes have failed.</p>

Shasta Kota
<p>EDIT 2: I eventually managed to resolve the final remaining issue. When you deploy multiple replica sets using this method, you must make sure they each have a unique value for scramCredentialsSecretName.</p>
<p><s>EDIT: Actually, this didn't fix the entire problem. It seems to work for a few hours then all the readiness probes for all rs start to fail again.</s></p>
<p>It looks like you can deploy multiple operators and rs in a single namespace. What I was missing was linking the operators and rs together.</p>
<p>I also left out an important detail. I don't actually deploy the mongodb using that helm chart because the config options are too limited. At the bottom of the values.yaml there's a setting called <code> createResource: false</code> which I have set to false. I then deploy a separate yaml that defines the mongo replicaset like so:</p>
<pre><code>apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: my-mongo-rs
spec:
  members: 3
  type: ReplicaSet
  version: &quot;5.0.5&quot;
  security:
    authentication:
      modes: [&quot;SCRAM&quot;]
    # tls:
    #   enabled: true
    #   certificateKeySecretRef:
    #     name: mongo-tls
    #   caConfigMapRef:
    #     name: mongo-ca
  statefulSet:
    spec:
      template:
        spec:
          containers:
            - name: &quot;mongodb-agent&quot;
              resources:
                requests:
                  cpu: 200m
                  memory: 500M
                limits: {}
            - name: &quot;mongod&quot;
              resources:
                requests:
                  cpu: 1000m
                  memory: 5G
                limits: {}
          serviceAccountName: my-mongodb-database
      volumeClaimTemplates:
      - metadata:
          name: data-volume
        spec:
          storageClassName: my-retainer-sc
          accessModes: [ &quot;ReadWriteOnce&quot; ]
          resources:
            requests:
              storage: 20G
  # replicaSetHorizons:
  #   - external: myhostname.com:9000
  #   - external: myhostname.com:9001
  #   - external: myhostname.com:9002
  users:
    - name: my-mongo-user
      db: admin
      passwordSecretRef: # a reference to the secret that will be used to generate the user's password
        name: my-mongo-user-creds
      roles:
        - db: admin
          name: clusterAdmin
        - db: admin
          name: readWriteAnyDatabase
        - db: admin
          name: dbAdminAnyDatabase
        - db: admin
          name: userAdminAnyDatabase
        - db: admin
          name: root
      scramCredentialsSecretName: my-user-scram
  additionalMongodConfig:
    storage.wiredTiger.engineConfig.journalCompressor: zlib
</code></pre>
<p>Anywhere in this config where you see &quot;my&quot;, I actually use my app name but I've genericized it for this post.</p>
<p>To link the operator and rs together, it's done using a name. In the operator yaml it's this line:</p>
<pre><code>database:
  name: my-mongodb-database
</code></pre>
<p>That name creates a serviceaccount in kubernetes and you must define your database pod to use that specific serviceaccount. Otherwise, it tries to default to a serviceaccount named mongodb-database which either won't exist, or you'll end up with multiple rs using the same serviceaccount (therefore, the same operator).</p>
<p>And in the rs yaml it's this line:</p>
<pre><code>serviceAccountName: my-mongodb-database
</code></pre>
<p>This will link it to the correct serviceaccount.</p>
