K8SPSMDB-1608: add externaldns anotation to create dns for created loadbalancer#2280
K8SPSMDB-1608: add externaldns anotation to create dns for created loadbalancer#2280myJamong wants to merge 9 commits intopercona:mainfrom
Conversation
| // +kubebuilder:validation:Required | ||
| Prefix string `json:"prefix"` |
There was a problem hiding this comment.
maybe prefix shouldn't be required and operator should use the cluster name by default
There was a problem hiding this comment.
I think its a great idea. I changed it to have default cr name - ee194e4
| if dns.Prefix == "" || dns.Domain == "" { | ||
| return errors.Errorf("externalDNS requires both prefix and domain for replset %s", rs.Name) | ||
| } |
There was a problem hiding this comment.
even though this will be handled on CRD level, I think we should do this check in CheckNSetDefaults
There was a problem hiding this comment.
I moved the validation logic - 19a85b2
Thanks for the review!
…unctions to CheckNSetDefaults.
|
@myJamong please fix manifests by running |
| if rs.Expose.ExternalDNS != nil && !rs.Expose.Enabled { | ||
| log.Info("externalDNS is configured but expose is not enabled, skipping DNS annotations", "replset", rs.Name) | ||
| } |
There was a problem hiding this comment.
Will this get logged on every reconciliation?
There was a problem hiding this comment.
@mayankshah1607
You're right, this fires every reconcile. The log prints about every ~11s (default reconcile interval) and it is quite noisy.
Let me change it back to just silently skip when expose is disabled.
Thanks for catching this.
commit: abd5cfa |
CHANGE DESCRIPTION
Problem:
When
expose.enabled: truewithtype: 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 existingexpose.annotationsfield applies the same annotations to every per-pod Service, making it impossible to assign a uniqueexternal-dns.alpha.kubernetes.io/hostnameper 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
externalDNSfield underexposethat automatically generates uniqueexternal-dns.alpha.kubernetes.io/hostnameannotations 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
Generated Annotations
Each per-pod Service gets a unique hostname annotation:
my-cluster-rs0-0external-dns.alpha.kubernetes.io/hostname: service-name-rs0-0.mongo.example.commy-cluster-rs0-1external-dns.alpha.kubernetes.io/hostname: service-name-rs0-1.mongo.example.commy-cluster-rs0-2external-dns.alpha.kubernetes.io/hostname: service-name-rs0-2.mongo.example.comIf
ttlis set, theexternal-dns.alpha.kubernetes.io/ttlannotation is also added.Supported Components
{prefix}-{replsetName}-{podIndex}.{domain}{prefix}-mongos-{podIndex}.{domain}{prefix}-mongos.{domain}Note on
serviceAnnotationsoverlapIf
serviceAnnotationscontainsexternal-dns.alpha.kubernetes.io/hostname, theexternalDNSconfig takes precedence and overwrites it. This is by design — whenexternalDNSis configured, it owns the hostname annotation.CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
compare/*-oc.yml)?Config/Logging/Testability