# PerconaServerMongoDB CR design considerations around \`expose\` and \`externalNodes\`

**URL:** <https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896>\
**Category:** Percona Operator for MongoDB\
**Created:** [October 7, 2022, 5:45am UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896 "2022-10-07T05:45:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vitaly\_Orbidan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vitaly_orbidan/32/7979_2.png) [@Vitaly\_Orbidan](https://forums.percona.com/u/Vitaly_Orbidan)\
**Post date:** [October 7, 2022, 5:45am UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/1 "2022-10-07T05:45:17Z")

</div>

The ability to add `spec.replsets[].externalNodes` depends on `spec.replsets[].expose.enabled: true`, so in order to be able to add `externalNodes` one also needs to expose replica sets with a service-per-pod or MCS.

I quite, honestly do not understand why there is such a dependency.

Also, the `psmdb.MongoHost` is used to calculate the name of the host to be added to replicaset, config replicaset and shards, but it depends on whether it is exposed or not, and even more so on _how_ it is exposed, with variants around `spec.multiCluster` and `spec.clusterServiceDNSMode`, which are not a part of either `spec.replsets[].expose` or `spec.sharding.configReplSet.expose`.

So, IMO, there are 2 issues, which are interconnected:

1. The ability to add external nodes when replicasets are not exposed

2. The way replicaset names are calculated based on the type of exposure

While I am not too sure how to address #2 (and even if it needs to be addressed), can someone help me understand why we cannot add external nodes if replicasets are not exposed?

---

<div class="post-metadata">

**Author:** ![Ege\_Gunes](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ege_gunes/32/4595_2.png) [@Ege\_Gunes](https://forums.percona.com/u/Ege_Gunes)\
**Post date:** [October 7, 2022, 6:52am UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/2 "2022-10-07T06:52:19Z")

</div>

Hi @Vitaly_Orbidan,

Cross site replication a.k.a external nodes are mainly introduced for enabling replication between two different k8s clusters or between on-prem instances and k8s. Mongo nodes needs to be able to reach each other in replicaset. You need to expose your replica and primary clusters for that. The decision to force exposing the replicaset is there for making misconfigurations hard.

Do you want to add external nodes from separate namespace that runs in the same Kubernetes cluster? What’s your use case?

---

<div class="post-metadata">

**Author:** ![Vitaly\_Orbidan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vitaly_orbidan/32/7979_2.png) [@Vitaly\_Orbidan](https://forums.percona.com/u/Vitaly_Orbidan)\
**Post date:** [October 7, 2022, 1:27pm UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/3 "2022-10-07T13:27:10Z")

</div>

Hello Ege,  
Thank you for getting back - really appreciate it.  
So, in my case I already have a a pod-to-pod connectivity between multiple k8s clusters via cilium mesh, and pods can reach each other. so in my case the default MongoHost name is perfect, I just need to add external pod names, which can be addressed like `<pod-name>.<headless-service-name>.<namespace>.<domain-suffix>`.  
And here I could have the remote db cluster deployed to the different namespace, or use a different domain suffix.

---

<div class="post-metadata">

**Author:** ![Vitaly\_Orbidan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vitaly_orbidan/32/7979_2.png) [@Vitaly\_Orbidan](https://forums.percona.com/u/Vitaly_Orbidan)\
**Post date:** [October 7, 2022, 1:30pm UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/4 "2022-10-07T13:30:54Z")

</div>

Also, now that we are getting to multiple “exposure” scenarios, like MCS, ServiceMesh, ClusterMesh (with cilium), etc. I think that some re-factoring around the CRD and MongHost may be warranted…

---

<div class="post-metadata">

**Author:** ![surajm](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@surajm](https://forums.percona.com/u/surajm)\
**Post date:** [March 19, 2025, 5:56pm UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/5 "2025-03-19T17:56:06Z")

</div>

Hi @Vitaly_Orbidan ,  
Did you get it working ?  
I am also looking for similar use case with Istio Mesh here.

Use case is multi shard, multi replica and multi Primary in different k8s clusters connected via Istio mesh.  
As per my understanding, with cross-site replication mechanism, it will have writes capabilities to one Master Cluster only and all other cluster(s) will be in read only mode.  
Can I have write capabilities on different clusters ?

---

<div class="post-metadata">

**Author:** ![Vitaly\_Orbidan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vitaly_orbidan/32/7979_2.png) [@Vitaly\_Orbidan](https://forums.percona.com/u/Vitaly_Orbidan)\
**Post date:** [March 19, 2025, 8:28pm UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/6 "2025-03-19T20:28:19Z")

</div>

Hello @surajm,  
I think we have resolved this issue back in 2023, here is a link to the PR:

> <https://github.com/percona/percona-server-mongodb-operator/pull/1115>
>
> \[!\[K8SPSMDB-817\](https://badgen.net/badge/JIRA/K8SPSMDB-817/green)\](https://jira….percona.com/browse/K8SPSMDB-817) \[\<img width="16" alt="Powered by Pull Request Badge" src="https://user-images.githubusercontent.com/1393946/111216524-d2bb8e00-85d4-11eb-821b-ed4c00989c02.png"\>\](https://pullrequestbadge.com/?utm\_medium=github&utm\_source=percona&utm\_campaign=badge\_info)
> 
> https://jira.percona.com/browse/K8SPSMDB-817
> 
> Test covers the ability to form a replicaset with one main member and few external members. 
> Replicaset members are not exposed with k8s services, but rather use a statefulset notation for registering external nodes.
> 
> \*\*CHANGE DESCRIPTION\*\*
> \---
> \*\*Problem:\*\*
> Need the ability to add external replicaset members when the replicaset is not exposed via k8s service
> 
> \*\*Cause:\*\*
> PSMDB Controller fails the PSMDB cluster creation when the external nodes are specified for replicaset, but replicaset is not exposed via k8s service
> 
> \*\*Solution:\*\*
> Log an INFO message with an advise to expose replicaset members with services instead of failing.
> 
> This allows to bootstrap a PSMDB cluster with replicaset members deployed to different k8s clusters without exposing replicaset members via k8s services.
> 
> It is the responsibility of a k8s platform operations to establish clustermesh (i.e. cilium) for pod-to-pod connectivity across multiple k8s clusters.
> 
> \*\*CHECKLIST\*\*
> \---
> \*\*Jira\*\*
> \- \[x\] Is the Jira ticket created and referenced properly?
> \- \[\] Does the Jira ticket have the proper statuses for documentation (\`Needs Doc\`) and QA (\`Needs QA\`)?
> \- \[\] Does the Jira ticket link to the proper milestone (Fix Version field)?
> 
> \*\*Tests\*\*
> \- \[x\] Are E2E tests passing?
> \- \[\] Are unit tests passing?
> \- \[\] Are linting tests passing?
> \- \[x\] Is an E2E test/test case added for the new feature/change?
> \- \[\] Are unit tests added where appropriate?
> \- \[\] Are OpenShift compare files changed for E2E tests (\`compare/\*-oc.yml\`)?
> 
> \*\*Config/Logging/Testability\*\*
> \- \[\] Are all needed new/changed options added to default YAML files?
> \- \[\] Are the manifests (crd/bundle) regenerated if needed?
> \- \[\] Did we add proper logging messages for operator actions?
> \- \[\] Did we ensure compatibility with the previous version or cluster upgrade process?
> \- \[\] Does the change support oldest and newest supported MongoDB version?
> \- \[\] Does the change support oldest and newest supported Kubernetes version?

I, unfortunately, stopped working on that POC, as I switched teams, so, yes - I remember solving it, but do not have a working config to share with you…

---

<div class="post-metadata">

**Author:** ![surajm](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@surajm](https://forums.percona.com/u/surajm)\
**Post date:** [March 20, 2025, 7:19am UTC](https://forums.percona.com/t/perconaservermongodb-cr-design-considerations-around-expose-and-externalnodes/17896/7 "2025-03-20T07:19:09Z")

</div>

Thanks @Vitaly_Orbidan for the pointer. I will try it and reach out to community if any further help is needed here.
