How to set a Domain Name for a Load Balancer Service on AKS

6/8/2019

What is the process to assign a DNS record to a Load balanced service.

I have created a simple service of Type LoadBalancer on AKS. The service gets a external IP assigned and points to pods hosting a sample hello world application.

How do I browse my application using a DNS name, or setup the DNS name for the service in the first place. I can successfully browse to IP.

Service yml

apiVersion: v1
kind: Service
metadata:
 name: transactionapi-svc
 labels:
   version: v1
spec:
 type: LoadBalancer
 ports:
  - name: http
    port: 80
  - name: https
    port: 443
 selector:
  app: transaction-api
-- Anuj Pant
azure
azure-aks
azure-kubernetes
kubernetes

4 Answers

3/4/2020

the best way is to use annotations in the metadata, I test it and don't work if the service exist and you apply, you need first to delete the svc and recreate with this metadata.

like this example:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-dns-label-name: $label-name
-- Cesar Seijas
Source: StackOverflow

6/8/2019

there is no process for that built-in to kubernetes. you need to do that either externally, say with pulumi, or you need to use external-dns. It scans your ingress definitions and applies matching A record to the configured dns domain.

So what happens it finds the ingress resources, finds the hosts it is associated to it, finds the IP address and creates an A record in the dns that's matching the host and that targets the IP address ingress listens on.

-- 4c74356b41
Source: StackOverflow

2/29/2020

There is another way if you host your DNS on Azure as well.

When you define a LoadBalancer (as you have) in the service and deploy, AKS auto-assigns a public IP. Additionally, it also creates an "alias" record.

In the Azure DNS service, you can map a new record set to this alias record. I don't know how this is managed in the backend on Azure. If someone from Azure team can provide additional detail, that would be great.

-- Zaifworks
Source: StackOverflow

6/13/2019

For your issue, you can create the service with Load Balancer type and use a static Load Balancer IP which you create with the DNS name as you wish before. Then there is an FQDN for the external IP and both the IP and FQDN can access the application in the AKS pod.

Follow the steps in Use a static public IP address with the Azure Kubernetes Service (AKS) load balancer, take care, when you create the public IP using the CLI command az network public-ip create, do not forget to add the parameter --dns-name.

-- Charles Xu
Source: StackOverflow