8

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
4c74356b41
  • 69,186
  • 6
  • 100
  • 141
APSR
  • 83
  • 1
  • 1
  • 4

4 Answers4

8

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
criptodev
  • 89
  • 1
  • 2
  • FYI: If you do this directly, you get the error: The domain name label $label-name is invalid. It must conform to the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$. I'm assuming $label-name in this example is a template parameter? For the most recent docs, see here: https://learn.microsoft.com/en-us/azure/aks/static-ip#apply-a-dns-label-to-the-service – ndtreviv Mar 24 '21 at 10:49
  • Where $label-name is a variable, replace it with the value you are looking for. – criptodev Nov 22 '21 at 16:28
4

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
  • 29,862
  • 2
  • 22
  • 39
2

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
  • 69,186
  • 6
  • 100
  • 141
  • Thanks for answering. Let me rephrase, is there any other way to access the service except for the external IP. Does Kubernetes assign any fqdn that I can use? I dont need a custom DNS entry, just something to access the service apart from the IP. – APSR Jun 08 '19 at 08:59
  • this makes no sense. there is no way to access a service except for ip or dns name. at least I dont know any other way. kubernetes doesnt assign any dns name to the endpoints. you might take a look at the [HTTP application routing addon](https://learn.microsoft.com/en-us/azure/aks/http-application-routing) which more or less is an alternative to external-dns, but a lousy one. – 4c74356b41 Jun 08 '19 at 11:23
1

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
  • 73
  • 5