Using custom DNS server for domain specific name resolution with Azure Kubernetes Service

Just a short blog post about a small challenge I had these days. If you want to specify a custom DNS server for domain specific name resolution with AKS, you can do so.

The necessary steps are already described in the Kubernetes documentation.

-> https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/

Define a config map and apply it to your AKS cluster in Azure. The following one is an example on how to do it.

First deploy a pod in your AKS cluster for name resolution testing. I have used the following example of a busybox container.

apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  containers:
  - name: busybox
    image: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always

My scenario was, that I wanted to have the name resolution for the following test domain azure.local. So, AKS cannot resolve it by default, because it is not a standard TLD that is known by the DNS system.

customDNS01

Moving on with the config map definition as described in the Kubernetes documentation, I am providing the AKS cluster with the necessary information on how to contact the custom DNS server for this specific domain. The DNS server sits in another VNET in Azure which is connected via VNET peering with the AKS VNET.

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-dns
  namespace: kube-system
data:
  stubDomains: |
    {"azurestack.local": ["172.16.0.4"]}

After seconds I am now able to resolve the domain azure.local and its records.

customDNS02

When to use it? Especially in hybrid cloud use cases, where you need to be able to resolve names in AKS to reach on-premises resources.

Facebooktwittergoogle_pluslinkedinmail