External access: setting DNS name annotations on generated services for external-dns operator

From the documentation for the MongoDB resource, which is deployed by the operator, I’ve successfully added annotations that apply across each service created for each replica in my cluster.

For integration with the external-dns operator (to create DNS names for each LoadBalancer service’s IP), is there a way to specify that each service created by the operator should have an annotation containing the DNS name for that specific instance? I’ve reviewed the docs at length and it seems I can only apply annotations that have a shared value across each generated service.

For example I have something like the following in the MongoDB resource spec:

apiVersion: mongodb.com/v1
kind: MongoDB
  name: mymongodb
      - "external": "mydb-db-0.my-domain.com:27017"
      - "external": "mydb-db-1.my-domain.com:27017"
      - "external": "mydb-db-2.my-domain.com:27017"
        service.beta.kubernetes.io/azure-load-balancer-internal-subnet: mysubnet

In the above scenario, the annotation is added equally to each generated service.

I want in the MongoDB resource spec to be able to define an annotation with a distinct value for each service. For example I want generated service “mydb-db-0-svc-external” to have annotation:

external-dns.alpha.kubernetes.io/hostname: mydb-db-0.my-domain.com

Whereas service “mydb-db-1-svc-external” would have annotation:

external-dns.alpha.kubernetes.io/hostname: mydb-db-1.my-domain.com


Right now there’s unfortunately no way to achieve this.

The only option is to create your services manually with that annotation in place.

But it is something we’re planning to support at some point in the futre.

It would be great if you could raise a feedback idea for this here: feedback.mongodb.com as when we update it there, you’d then get notified!

Requested, and thank you for the feedback. A lot of times it helps to just be told “you can’t do that” so I can move on to other ways. It is working for me to create the services with distinct annotations separately, before applying the MongoDB resource spec.