# exposeType : LoadBalancer queries for percona Mongo k8s operator

**URL:** <https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633>\
**Category:** Percona Operator for MongoDB\
**Tags:** community, troubleshooting, percona, mongodb, new-release, kubernetes\
**Created:** [August 2, 2021, 3:30pm UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633 "2021-08-02T15:30:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adithya](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Adithya](https://forums.percona.com/u/Adithya)\
**Post date:** [August 2, 2021, 3:30pm UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/1 "2021-08-02T15:30:29Z")

</div>

Hi Team,

We are trying percona operator for MongoDB with exposeType : LoadBalancer in our development servers using AWS EKS

We have below queries reg the loadbalencers :

1. LB name

mongo1-cdbr1-0 LoadBalancer 10.100.80.36 [a7c9d1c2f2df14ab3959e7f87dc48f3b-755583469.us-east-2.elb.amazonaws.com](http://a7c9d1c2f2df14ab3959e7f87dc48f3b-755583469.us-east-2.elb.amazonaws.com) 27017:32365/TCP 38m  
mongo1-cdbr1-1 LoadBalancer 10.100.115.217 [a8b8a778816b841f990c8f21a63cefa4-705224816.us-east-2.elb.amazonaws.com](http://a8b8a778816b841f990c8f21a63cefa4-705224816.us-east-2.elb.amazonaws.com) 27017:32238/TCP 38m  
mongo1-cdbr1-2 LoadBalancer 10.100.56.73 [ae1bd4452e7464f989e9ddc304870a97-1759599640.us-east-2.elb.amazonaws.com](http://ae1bd4452e7464f989e9ddc304870a97-1759599640.us-east-2.elb.amazonaws.com) 27017:31734/TCP 37m

We can see LB names are created with random names → **a7c9d1c2f2df14ab3959e7f87dc48f3b-755583469 / a8b8a778816b841f990c8f21a63cefa4-705224816 / ae1bd4452e7464f989e9ddc304870a97-1759599640**

Is there any way to setup custom names like **“mongo1-cdbr-lb”** for the load balencers for exposing outside the cluster ?

Please suggest to configure custom names for the load balencers .

1. Single ALB instead of multiple loadbalencers tagged to services

Is there any way to configure single load balencer(which servers as dns-srv name) for all the services which are tagged to pods of replicaset.

Eg : mongo1-cdbr-lb (single ALB) which should route the traffic to all the services for replicaset using mongodb+srv from outside the cluster .

Regards,  
Adithya

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [August 2, 2021, 8:18pm UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/2 "2021-08-02T20:18:48Z")

</div>

Hello @Adithya .

> Is there any way to setup custom names like **“mongo1-cdbr-lb”** for the load balencers for exposing outside the cluster ?

We rely on regular Kubernetes primitives - so we just create a service object of a specific type. I’m not aware of being able to specify the LB name through k8s right now.

> 1. Single ALB instead of multiple loadbalencers tagged to services

Single ALB will not solve the problem. Behind this ALB there should be multiple SVR records pointing to different servers, otherwise it does not make much sense.  
In general our recommendation is to enable sharding and expose mongos nodes through a single load balancer. You will have one sharded mongoDB cluster with single entry-point.

---

<div class="post-metadata">

**Author:** ![Adithya](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Adithya](https://forums.percona.com/u/Adithya)\
**Post date:** [August 3, 2021, 7:09am UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/3 "2021-08-03T07:09:21Z")

</div>

@Sergey_Pronin Thanks for the reply.

> [@Sergey\_Pronin](#):
>
> In general our recommendation is to enable sharding and expose mongos nodes through a single load balancer. You will have one sharded mongoDB cluster with single entry-point.

Can we know how to setup single load balancer for replicaset/sharded cluster ? Can you provide some sample yaml file

If we add exposeType: LoadBalancer it’s creating multiple load balancers in AWS as mentioned above.

Regards,  
Adithya

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [August 3, 2021, 7:37am UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/4 "2021-08-03T07:37:39Z")

</div>

Hey @Adithya ,

as I mentioned it can be done through enabling sharding.  
In a nutshell the key options would look like this:

```auto
spec.replsets.[].explose.enabled: false
spec.sharding.enabled: true
spec.sharding.mongos.expose.exposeType: LoadBalancer

```

This will enable sharding and expose mongos pods through a single load balancer (and as a result the whole MongoDB cluster).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Adithya](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Adithya](https://forums.percona.com/u/Adithya)\
**Post date:** [August 3, 2021, 3:40pm UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/5 "2021-08-03T15:40:59Z")

</div>

Thanks @Sergey_Pronin for the all the details. Appreciate quick response.

So for Replicaset config with cr.yaml with k8s operator we will not be able to setup single LB.

Single load balancer setup works for sharded cluster.

mgdb-mongos LoadBalancer 10.100.137.171 [a638c75f9e74d4054840a40023c1c539-863770566.us-east-2.elb.amazonaws.com](http://a638c75f9e74d4054840a40023c1c539-863770566.us-east-2.elb.amazonaws.com) 27017:32493/TCP 7m29s

From AWS EC2 console : we can see random DNS name is used for CLB. Is there any way to setup DNS Name from the cr.yaml while creating LB from EKS .

Name → a638c75f9e74d4054840a40023c1c539  
DNS name → [a638c75f9e74d4054840a40023c1c539-863770566.us-east-2.elb.amazonaws.com](http://a638c75f9e74d4054840a40023c1c539-863770566.us-east-2.elb.amazonaws.com) (A Record)

Regards,  
Adithya

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [August 3, 2021, 4:23pm UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/6 "2021-08-03T16:23:15Z")

</div>

For the name, please see this: [Annotations - AWS Load Balancer Controller](https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/guide/service/annotations/#load-balancer-name)

Looks like AWS load balancer controller supports that through the annotation `service.beta.kubernetes.io/aws-load-balancer-name`

So just add under `spec.sharding.mongos.expose.serviceAnnotations` smth like `service.beta.kubernetes.io/aws-load-balancer-name: my-lb-name`

---

<div class="post-metadata">

**Author:** ![Adithya](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Adithya](https://forums.percona.com/u/Adithya)\
**Post date:** [August 4, 2021, 8:58am UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/7 "2021-08-04T08:58:55Z")

</div>

@Sergey_Pronin

Tried the option like below but no luck. still LB name is random.

```
  expose:
    exposeType: LoadBalancer
    serviceAnnotations:
      service.beta.kubernetes.io/aws-load-balancer-name: awslb

```

&

```
  expose:
    exposeType: LoadBalancer
    serviceAnnotations:
      service.beta.kubernetes.io/load-balancer-name: awslb

```

For sharded cluster:  
service/mgdb-mongos LoadBalancer 10.100.17.221 [a726464f38ba044e0ab8ce1bdf7011e4-1633854664.us-east-2.elb.amazonaws.com](http://a726464f38ba044e0ab8ce1bdf7011e4-1633854664.us-east-2.elb.amazonaws.com) 27017:31050/TCP 11m

Replicaset:  
service/mongo-cdbrs-0 LoadBalancer 10.100.2.27 [aec6d9995a39744dcb408481b9dd0005-2042329951.us-east-2.elb.amazonaws.com](http://aec6d9995a39744dcb408481b9dd0005-2042329951.us-east-2.elb.amazonaws.com) 27017:30790/TCP 11m  
service/mongo-cdbrs-1 LoadBalancer 10.100.54.208 [a4127e81a13bc40f0a5a1015a0910921-316818886.us-east-2.elb.amazonaws.com](http://a4127e81a13bc40f0a5a1015a0910921-316818886.us-east-2.elb.amazonaws.com) 27017:30516/TCP 11m  
service/mongo-cdbrs-2 LoadBalancer 10.100.248.122 [aa1f0620357d34ae8b34e6d1be1c6b6c-1226402236.us-east-2.elb.amazonaws.com](http://aa1f0620357d34ae8b34e6d1be1c6b6c-1226402236.us-east-2.elb.amazonaws.com) 27017:32593/TCP 10m

~Adithya

---

<div class="post-metadata">

**Author:** ![Adithya](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@Adithya](https://forums.percona.com/u/Adithya)\
**Post date:** [August 10, 2021, 7:06am UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/8 "2021-08-10T07:06:12Z")

</div>

@Sergey_Pronin  
Can this feature of having single LB (with custom name) for both replicaset and sharded cluster be included in future versions of percona operator ?

Regards,.  
Adithya

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [August 10, 2021, 7:36am UTC](https://forums.percona.com/t/exposetype-loadbalancer-queries-for-percona-mongo-k8s-operator/11633/9 "2021-08-10T07:36:23Z")

</div>

If we talk about one load balancer + multiple replica set nodes - the load balancer must be aware where Primary is and handle the failover.  
Or if we talk about SRV records - load balancer does not help as well, as these SRV records would be pointing to internal IP-addresses in k8s networking.

How do you see it working?
