kubernetes-sigs / external-dns

Configure external DNS servers (AWS Route53, Google CloudDNS and others) for Kubernetes Ingresses and Services
Apache License 2.0
7.69k stars 2.56k forks source link

Add support for "target" annotation on ingress service #4627

Open Deltachaos opened 3 months ago

Deltachaos commented 3 months ago

What would you like to be added:

external-dns should use the external-dns.alpha.kubernetes.io/target annotation of the Ingress Service for Ingress objects if defined.

Why is this needed:

If you run your Ingress as a ClusterIP Service and the individual Pods with hostNetwork: true, the real external IP for the ingress controller cannot be determined. In this case, you are able to specify external-dns.alpha.kubernetes.io/target on each Ingress object you create. This information is redundant. external-dns should not use the IP from the ClusterIP Service but instead should use the overwritten IP from the external-dns.alpha.kubernetes.io/target annotation of the ingress controller's ClusterIP Service.

AayushVinayDev commented 3 months ago

Hi @Deltachaos :D , I'm new to this codebase so from my very limited understanding. Is this the change you are suggesting?

case v1.ServiceTypeClusterIP:
            if svc.Spec.ClusterIP == v1.ClusterIPNone {
                endpoints = append(endpoints, sc.extractHeadlessEndpoints(svc, hostname, ttl)...)
            } else if useClusterIP || sc.publishInternal {
                targets = extractServiceIps(svc)
            }
            // Check if the service has the external-dns.alpha.kubernetes.io/target annotation
            if target, ok := svc.Annotations["external-dns.alpha.kubernetes.io/target"]; ok {
                targets = endpoint.Targets{target}
            }

if ClusterIP is true, use the external-dns.alpha.kubernetes.io/target annotation from ingress controller's ClusterIP Service.

Please let me know of my shortcomings! Thanks

Deltachaos commented 3 months ago

I am probably the wrong person to ask, as im not into the code of this project as well, and im currently working on getting some Go skills, but: From my understanding this seems to go in the right direction.

k8s-triage-robot commented 2 weeks ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

rvaidya commented 6 days ago

I have a similar use case - MetalLB is reporting the internal NAT IP as the IP for the load balancer, which is then being published as an A record by external-dns.

I'd like to override this with a CNAME record that points to a dns record that automatically gets updated by a dynamic DNS client, since public IP changes on home internet.

This PR seems tangentially related, but has been closed: https://github.com/kubernetes-sigs/external-dns/pull/1077

fiskhest commented 4 days ago

I have a similar use case - MetalLB is reporting the internal NAT IP as the IP for the load balancer, which is then being published as an A record by external-dns.

I'd like to override this with a CNAME record that points to a dns record that automatically gets updated by a dynamic DNS client, since public IP changes on home internet.

This PR seems tangentially related, but has been closed: #1077

I have the exact same use case. For the time being, I've worked around it by disabling external-dns from picking up ingresses by commenting --source=ingress, then create a ExternalName service for each ingress:

kind: Service
apiVersion: v1
metadata:
  name: service-external-dns
  annotations:
    external-dns.alpha.kubernetes.io/hostname: foo.domain.com
spec:
  type: ExternalName
  externalName: ddns-record.domain.com

The ddns-record is managed by a separate ddns-client.

This stops external-dns from trying to publish an A record with the (NATed) IP that is bound to the ingress and instead publish a CNAME record for value of external-dns.alpha.kubernetes.io/hostname pointing to externalName. https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/externalname.md

Preferably, external-dns would read external-dns.alpha.kubernetes.io/target on an ingress object and understand that the host specified in the ingress should be a CNAME to the target, instead of an A record to the IP.