sigs.k8s.io/external-dns@v0.14.1/docs/tutorials/aws-load-balancer-controller.md (about) 1 # Using ExternalDNS with aws-load-balancer-controller 2 3 This tutorial describes how to use ExternalDNS with the [aws-load-balancer-controller][1]. 4 5 [1]: https://kubernetes-sigs.github.io/aws-load-balancer-controller 6 7 ## Setting up ExternalDNS and aws-load-balancer-controller 8 9 Follow the [AWS tutorial](aws.md) to setup ExternalDNS for use in Kubernetes clusters 10 running in AWS. Specify the `source=ingress` argument so that ExternalDNS will look 11 for hostnames in Ingress objects. In addition, you may wish to limit which Ingress 12 objects are used as an ExternalDNS source via the `ingress-class` argument, but 13 this is not required. 14 15 For help setting up the AWS Load Balancer Controller, follow the [Setup Guide][2]. 16 17 [2]: https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/installation/ 18 19 Note that the AWS Load Balancer Controller uses the same tags for [subnet auto-discovery][3] 20 as Kubernetes does with the AWS cloud provider. 21 22 [3]: https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/subnet_discovery/ 23 24 In the examples that follow, it is assumed that you configured the ALB Ingress 25 Controller with the `ingress-class=alb` argument (not to be confused with the 26 same argument to ExternalDNS) so that the controller will only respect Ingress 27 objects with the `ingressClassName` field set to "alb". 28 29 ## Deploy an example application 30 31 Create the following sample "echoserver" application to demonstrate how 32 ExternalDNS works with ALB ingress objects. 33 34 ```yaml 35 apiVersion: apps/v1 36 kind: Deployment 37 metadata: 38 name: echoserver 39 spec: 40 replicas: 1 41 selector: 42 matchLabels: 43 app: echoserver 44 template: 45 metadata: 46 labels: 47 app: echoserver 48 spec: 49 containers: 50 - image: gcr.io/google_containers/echoserver:1.4 51 imagePullPolicy: Always 52 name: echoserver 53 ports: 54 - containerPort: 8080 55 --- 56 apiVersion: v1 57 kind: Service 58 metadata: 59 name: echoserver 60 spec: 61 ports: 62 - port: 80 63 targetPort: 8080 64 protocol: TCP 65 type: NodePort 66 selector: 67 app: echoserver 68 ``` 69 70 Note that the Service object is of type `NodePort`. We don't need a Service of 71 type `LoadBalancer` here, since we will be using an Ingress to create an ALB. 72 73 ## Ingress examples 74 75 Create the following Ingress to expose the echoserver application to the Internet. 76 77 ```yaml 78 apiVersion: networking.k8s.io/v1 79 kind: Ingress 80 metadata: 81 annotations: 82 alb.ingress.kubernetes.io/scheme: internet-facing 83 name: echoserver 84 spec: 85 ingressClassName: alb 86 rules: 87 - host: echoserver.mycluster.example.org 88 http: &echoserver_root 89 paths: 90 - path: / 91 backend: 92 service: 93 name: echoserver 94 port: 95 number: 80 96 pathType: Prefix 97 - host: echoserver.example.org 98 http: *echoserver_root 99 ``` 100 101 The above should result in the creation of an (ipv4) ALB in AWS which will forward 102 traffic to the echoserver application. 103 104 If the `source=ingress` argument is specified, then ExternalDNS will create DNS 105 records based on the hosts specified in ingress objects. The above example would 106 result in two alias records being created, `echoserver.mycluster.example.org` and 107 `echoserver.example.org`, which both alias the ALB that is associated with the 108 Ingress object. 109 110 Note that the above example makes use of the YAML anchor feature to avoid having 111 to repeat the http section for multiple hosts that use the exact same paths. If 112 this Ingress object will only be fronting one backend Service, we might instead 113 create the following: 114 115 ```yaml 116 apiVersion: networking.k8s.io/v1 117 kind: Ingress 118 metadata: 119 annotations: 120 alb.ingress.kubernetes.io/scheme: internet-facing 121 external-dns.alpha.kubernetes.io/hostname: echoserver.mycluster.example.org, echoserver.example.org 122 name: echoserver 123 spec: 124 ingressClassName: alb 125 rules: 126 - http: 127 paths: 128 - path: / 129 backend: 130 service: 131 name: echoserver 132 port: 133 number: 80 134 pathType: Prefix 135 ``` 136 137 In the above example we create a default path that works for any hostname, and 138 make use of the `external-dns.alpha.kubernetes.io/hostname` annotation to create 139 multiple aliases for the resulting ALB. 140 141 ## Dualstack ALBs 142 143 AWS [supports][4] both IPv4 and "dualstack" (both IPv4 and IPv6) interfaces for ALBs. 144 The AWS Load Balancer Controller uses the `alb.ingress.kubernetes.io/ip-address-type` 145 annotation (which defaults to `ipv4`) to determine this. If this annotation is 146 set to `dualstack` then ExternalDNS will create two alias records (one A record 147 and one AAAA record) for each hostname associated with the Ingress object. 148 149 [4]: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#ip-address-type 150 151 Example: 152 153 ```yaml 154 apiVersion: networking.k8s.io/v1 155 kind: Ingress 156 metadata: 157 annotations: 158 alb.ingress.kubernetes.io/scheme: internet-facing 159 alb.ingress.kubernetes.io/ip-address-type: dualstack 160 name: echoserver 161 spec: 162 ingressClassName: alb 163 rules: 164 - host: echoserver.example.org 165 http: 166 paths: 167 - path: / 168 backend: 169 service: 170 name: echoserver 171 port: 172 number: 80 173 pathType: Prefix 174 ``` 175 176 The above Ingress object will result in the creation of an ALB with a dualstack 177 interface. ExternalDNS will create both an A `echoserver.example.org` record and 178 an AAAA record of the same name, that each are aliases for the same ALB.