Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Completed
Created by Guest
Created on Mar 5, 2021

Automatic labeling of pods by replicaset role (primary/secondary)

Hi, I think it would be great if the Operator could watch and automatically mark individual pods of statefulset with some label indicating whether the node is primary or secondary to be able to route service just to the primary instance (or load balance secondary instances for read-only access on one IP). Currently I use a script that periodically checks roles and adds label "mongodb-replicaset-role": "primary" or "secondary" and a service that uses this as a selector. EDIT: (I'm thinking about writing own operator for this instead of script; maybe it's the best way?) Motivation: Linode (and possibly others') kubernetes nodebalancer costs $10/month each; if you want to make public access to the database and you have 3 nodes, it's better to just configure the service to use primary pod only and you don't need to expose all 3 nodes ($30) Thanks!
  • ADMIN RESPONSE
    Aug 1, 2025
    Since this was raised we've added support for load balancer (rather than just nodeport). Since this would be one load balancer for the entire replica set, this may reduce the cost? https://www.mongodb.com/docs/kubernetes-operator/master/tutorial/connect-from-outside-k8s/ ( https://www.mongodb.com/docs/kubernetes-operator/master/tutorial/connect-from-outside-k8s/ ) Please let us know via a comment if this doesn't solve the need.
  • Attach files