Skip to content

K8SPSMDB-1608: add externaldns annotation to create dns for created loadbalancer#2280

Merged
hors merged 21 commits into
percona:mainfrom
myJamong:NO-TICKET-YET-add-externaldns-anotation
Jun 11, 2026
Merged

K8SPSMDB-1608: add externaldns annotation to create dns for created loadbalancer#2280
hors merged 21 commits into
percona:mainfrom
myJamong:NO-TICKET-YET-add-externaldns-anotation

Conversation

@myJamong

@myJamong myJamong commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

CHANGE DESCRIPTION

Problem:
When expose.enabled: true with type: LoadBalancer, each per-pod Service gets an auto-assigned LB hostname (e.g., a1b2c3d4e5.elb.amazonaws.com). These hostnames are not human-readable, long, and unpredictable. The existing expose.annotations field applies the same annotations to every per-pod Service, making it impossible to assign a unique external-dns.alpha.kubernetes.io/hostname per pod.

This is the issue I made: #2267

Cause:
There was no built-in mechanism to generate unique, per-pod DNS hostname annotations. Users had to manually manage DNS records for each pod's LoadBalancer endpoint.

Solution:
Add an optional externalDNS field under expose that automatically generates unique external-dns.alpha.kubernetes.io/hostname annotations for each per-pod Service, enabling ExternalDNS to create human-readable DNS records in any supported DNS provider (Route53, Cloud DNS, Azure DNS, etc.).

Configuration

replsets:
  - name: rs0
    size: 3
    expose:
      enabled: true
      type: LoadBalancer
      externalDNS:
        prefix: "service-name"                    # required
        domain: "mongo.example.com"       # required
        ttl: 300                          # optional

Generated Annotations

Each per-pod Service gets a unique hostname annotation:

Service Annotation
my-cluster-rs0-0 external-dns.alpha.kubernetes.io/hostname: service-name-rs0-0.mongo.example.com
my-cluster-rs0-1 external-dns.alpha.kubernetes.io/hostname: service-name-rs0-1.mongo.example.com
my-cluster-rs0-2 external-dns.alpha.kubernetes.io/hostname: service-name-rs0-2.mongo.example.com

If ttl is set, the external-dns.alpha.kubernetes.io/ttl annotation is also added.

Supported Components

Component Hostname Format
Replica sets {prefix}-{replsetName}-{podIndex}.{domain}
Config servers Same path as replica sets, fully supported
Mongos (ServicePerPod=true) {prefix}-mongos-{podIndex}.{domain}
Mongos (ServicePerPod=false) {prefix}-mongos.{domain}

Note on serviceAnnotations overlap

If serviceAnnotations contains external-dns.alpha.kubernetes.io/hostname, the externalDNS config takes precedence and overwrites it. This is by design — when externalDNS is configured, it owns the hostname annotation.

CHECKLIST

Jira

  • 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

  • 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 all needed new/changed options added to the Helm Chart?
  • 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?

@myJamong myJamong changed the title No ticket yet add externaldns anotation add externaldns anotation to create dns for created loadbalancer Mar 9, 2026
@egegunes egegunes changed the title add externaldns anotation to create dns for created loadbalancer K8SPSMDB-1608: add externaldns anotation to create dns for created loadbalancer Mar 10, 2026
Comment thread pkg/apis/psmdb/v1/psmdb_types.go Outdated
Comment on lines +1466 to +1467
// +kubebuilder:validation:Required
Prefix string `json:"prefix"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe prefix shouldn't be required and operator should use the cluster name by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its a great idea. I changed it to have default cr name - ee194e4

Comment on lines +36 to +38
if dns.Prefix == "" || dns.Domain == "" {
return errors.Errorf("externalDNS requires both prefix and domain for replset %s", rs.Name)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even though this will be handled on CRD level, I think we should do this check in CheckNSetDefaults

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the validation logic - 19a85b2

Thanks for the review!

@egegunes egegunes added this to the v1.23.0 milestone Mar 10, 2026
egegunes
egegunes previously approved these changes Mar 10, 2026
@egegunes

Copy link
Copy Markdown
Contributor

@myJamong please fix manifests by running make generate manifests VERSION=main

egegunes
egegunes previously approved these changes Mar 11, 2026
hors
hors previously approved these changes Apr 12, 2026
pooknull
pooknull previously approved these changes Apr 14, 2026
@hors hors self-requested a review May 15, 2026 12:38
hors
hors previously approved these changes May 15, 2026
@gkech gkech changed the title K8SPSMDB-1608: add externaldns anotation to create dns for created loadbalancer K8SPSMDB-1608: add externaldns annotation to create dns for created loadbalancer May 25, 2026
gkech
gkech previously approved these changes May 25, 2026
Comment thread pkg/apis/psmdb/v1/psmdb_types.go
mayankshah1607
mayankshah1607 previously approved these changes May 26, 2026
@myJamong myJamong dismissed stale reviews from egegunes, gkech, mayankshah1607, and hors via 3112f13 May 26, 2026 06:26
@mayankshah1607

Copy link
Copy Markdown
Member

@myJamong you'll need to run make generate manifests, can you also check the unit test failure?

Comment thread pkg/apis/psmdb/v1/psmdb_types.go Outdated
@github-actions github-actions Bot added the tests label Jun 4, 2026
@gkech

gkech commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@myJamong please check the failing unit tests

@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
arbiter passed 00:00:00
balancer passed 00:00:00
cert-management-policy passed 00:00:00
cross-site-sharded passed 00:00:00
custom-replset-name passed 00:00:00
custom-tls passed 00:00:00
custom-users-roles passed 00:00:00
custom-users-roles-sharded passed 00:00:00
data-at-rest-encryption passed 00:00:00
data-sharded passed 00:00:00
demand-backup passed 00:00:00
demand-backup-eks-credentials-irsa passed 00:00:00
demand-backup-fs passed 00:00:00
demand-backup-if-unhealthy passed 00:00:00
demand-backup-incremental-aws passed 00:00:00
demand-backup-incremental-azure passed 00:00:00
demand-backup-incremental-gcp-native passed 00:00:00
demand-backup-incremental-gcp-s3 passed 00:00:00
demand-backup-incremental-minio passed 00:00:00
demand-backup-incremental-sharded-aws passed 00:00:00
demand-backup-incremental-sharded-azure passed 00:00:00
demand-backup-incremental-sharded-gcp-native passed 00:00:00
demand-backup-incremental-sharded-gcp-s3 passed 00:00:00
demand-backup-incremental-sharded-minio passed 00:00:00
demand-backup-logical-minio-native-tls passed 00:00:00
demand-backup-physical-parallel passed 00:00:00
demand-backup-physical-aws passed 00:00:00
demand-backup-physical-azure passed 00:00:00
demand-backup-physical-gcp-s3 passed 00:00:00
demand-backup-physical-gcp-native passed 00:00:00
demand-backup-physical-minio passed 00:00:00
demand-backup-physical-minio-native passed 00:00:00
demand-backup-physical-minio-native-tls passed 00:00:00
demand-backup-physical-sharded-parallel passed 00:00:00
demand-backup-physical-sharded-aws passed 00:00:00
demand-backup-physical-sharded-azure passed 00:00:00
demand-backup-physical-sharded-gcp-native passed 00:00:00
demand-backup-physical-sharded-minio passed 00:00:00
demand-backup-physical-sharded-minio-native passed 00:00:00
demand-backup-sharded passed 00:00:00
demand-backup-snapshot passed 00:00:00
demand-backup-snapshot-vault passed 00:00:00
disabled-auth passed 00:00:00
expose-sharded passed 00:00:00
finalizer passed 00:00:00
ignore-labels-annotations passed 00:00:00
init-deploy passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
limits passed 00:00:00
liveness passed 00:00:00
mongod-major-upgrade passed 00:00:00
mongod-major-upgrade-sharded passed 00:00:00
monitoring-2-0 passed 00:00:00
monitoring-pmm3 passed 00:00:00
multi-cluster-service passed 00:16:21
multi-storage passed 00:00:00
non-voting-and-hidden passed 00:00:00
one-pod passed 00:00:00
operator-self-healing-chaos passed 00:00:00
pitr passed 00:00:00
pitr-physical passed 00:00:00
pitr-sharded passed 00:00:00
pitr-to-new-cluster passed 00:00:00
pitr-physical-backup-source passed 00:00:00
preinit-updates passed 00:00:00
pvc-auto-resize passed 00:00:00
pvc-resize passed 00:00:00
recover-no-primary passed 00:00:00
replset-overrides passed 00:00:00
replset-remapping passed 00:00:00
replset-remapping-sharded passed 00:00:00
rs-shard-migration passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
security-context passed 00:00:00
self-healing-chaos passed 00:00:00
service-per-pod passed 00:00:00
serviceless-external-nodes passed 00:00:00
smart-update passed 00:00:00
split-horizon passed 00:00:00
split-horizon-manual-tls passed 00:00:00
stable-resource-version passed 00:00:00
storage passed 00:00:00
tls-issue-cert-manager passed 00:00:00
unsafe-psa passed 00:00:00
upgrade passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-consistency-sharded-tls passed 00:00:00
upgrade-sharded passed 00:00:00
upgrade-partial-backup passed 00:00:00
users passed 00:00:00
users-vault passed 00:00:00
version-service passed 00:00:00
Summary Value
Tests Run 94/94
Job Duration 00:45:49
Total Test Time 00:16:21

commit: 43b99c0
image: perconalab/percona-server-mongodb-operator:PR-2280-43b99c0df

@hors hors merged commit c6631cf into percona:main Jun 11, 2026
15 checks passed
@hors

hors commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@myJamong thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants