How to make the ELB attach to a domain name in route53 in Kubernates deployments

12/24/2018

Currently I am doing deployment and creating a service with type loadbalancer. I can access the POD via the created ELB. Then using route 53 I am attaching the ELB with k8-test.abc.com using alias. Below is the snippet.

apiVersion: v1
kind: Service
metadata:
  name: %APP_FULL_NAME%-service-lb-http
  labels:
    appname: %APP_FULL_NAME%
    stage: %APP_ENV%
    component: app-kube-aws-elb
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "True"
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:us-east-1:XXXXXXXXXXXXX:certificate/XXXXXXXXXXXXXXX
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http

spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 443
    targetPort: 8080
    protocol: TCP
  selector:
    appname: %APP_FULL_NAME%
    stage: %APP_ENV%

But I was wondering is there any way by which I can do some changes on deployment and the ELB which will be created, automatically get attached to the k8-test.abc.com while creating.

-- gamechanger17
amazon-elb
kubernetes

2 Answers

12/24/2018

By default it won't be automatic. You'll get an external endpoint for your ELB and then have to point your route53 at it.

This can mean that you have to do the pointing again if you recreate the Service, though not the Deployment so you can stick to rolling upgrades to avoid having to do much repointing.

There are other options to avoid this though, including NLB, Ingress and the external-DNS incubator project. The external-DNS approach would automate the route53 setup. The Ingress and NLB options still involve route53 but at least make sure you only have to do it once. For more on the Ingress and NLB approaches see the SO question How to have the static ELB endpoint for kubernates deployments I'd especially suggest looking at Ingress as it will also give you future flexibility to apply routing rules using paths and headers and would only require ELB and route53 setup once for the whole cluster (which means you only pay for one ELB).

-- Ryan Dawson
Source: StackOverflow

12/24/2018

There is an Incubator project (read: you may use it, but don't complain if it breaks) called external-dns. I haven't used it myself, but it looks like it may do what you ask for. Among other DNS providers, it also offers support for Route53.

After set-up (here's the documentation on how to set-up external-dns on AWS), you can define a DNS name for a Service using the external-dns.alpha.kubernetes.io/hostname annotation:

apiVersion: v1
kind: Service
metadata:
  name: %APP_FULL_NAME%-service-lb-http
  labels:
    appname: %APP_FULL_NAME%
    stage: %APP_ENV%
    component: app-kube-aws-elb
  annotations:
    external-dns.alpha.kubernetes.io/hostname: k8-test.abc.com
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "True"
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:us-east-1:XXXXXXXXXXXXX:certificate/XXXXXXXXXXXXXXX
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 443
    targetPort: 8080
    protocol: TCP
  selector:
    appname: %APP_FULL_NAME%
    stage: %APP_ENV%

This will automatically create the respective DNS records that will alias the DNS name k8-test-abc.com to your ELB.

-- helmbert
Source: StackOverflow