This is relevant for Azure DevOps, GitHub Actions, or using kubectl via the CLI to interact with a private AKS cluster. I received an error message stating, "Unable to connect to the server: dial tcp: lookup <Cluster Name>-dns-rrxn45oq.19568f79-2d23-4df0-8d3e-f7e3e690d17b.privatelink.eastus.azmk8s.io on <Private DNS IP>:53: no such host"
I figured this out. If anyone is getting this error running kubectl from a vnet different than the cluster's vnet, you need to ensure the following:
- The vnets are peered. I tried otherwise but the nslookup showed it was lost in trying to resolve the IP address, especially if IPs overlap.
- The Private DNS zone created by the AKS cluster installation has a Virtual Network Link to the vnet where you run kubectl. To do this, perform the following:
- Select to Private DNS zones from your Azure Portal Homepage (for me, it was: https://portal.azure.com/#view/HubsExtension/BrowseResource/resourceType/Microsoft.Network%2FprivateDnsZones).
- Click on the Private DNS zone AKS created. In my case, it was "19568f79-2d23-4df0-8d3e-f7e3e690d17b.privatelink.eastus.azmk8s.io".
- Click on Virtual network links (under Settings in left-side pane).
- Click on the "+Add" button.
- Complete the form with your link name and select the virtual network you want to run kubectl (or Azure DevOps or your private GitHub Actions runner) from.
- Once completed, you can test running kubectl from a VM inside the vnet (you first need to run az aks get-credentials first).