<p>I am trying to expose a stateful mongo replica set running on my cluster for outside access.</p>

<p>I have three replicas and I have created a <code>LoadBalancer</code> service for each replica with the same <code>LoadBalancerIP</code> while incrementing the port sequentially from <code>10255</code> to <code>10257</code>.</p>

<pre><code>    apiVersion: v1
    kind: Service
    metadata:
      name: mongo-service-0
      namespace: datastore
      labels:
        app: mongodb-replicaset
   spec:
      loadBalancerIP: staticip
      type: LoadBalancer
      externalTrafficPolicy: Local
      selector:
        statefulset.kubernetes.io/pod-name: mongo-mongodb-replicaset-0
      ports:
        - protocol: TCP
          port: 10255
          targetPort: 27017
</code></pre>

<p>The issue is that only one service <code>mongo-service-0</code> is deployed successfully with static IP, the other timeout after a while.</p>

<p>What I am trying to figure out is if I can use a single static IP address as LoadBalancerIP across multiple services with different ports.</p>

<p>Since you are using different ports for each of your Mongo replicas you had to create different Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Services</a> for each one of the replicas.  You can only tie a Kubernetes service with a single load balancer and each load balancer will have its own unique IP (or IPs) address, so you won't be able to share that IP address across a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">LoadBalancer</a> type of Service.</p>

<p>The workaround is to use a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">NodePort</a> service and basically manage your load balancer independently and point it to the NodePort for each one of your replicas.</p>

<p>Another workaround is to use the same port on your Mongo replicas and use the same Kubernetes LoadBalancer service. Is there any reason why you are not using that?</p>
