Azure AKS get-credentials using wrong hostname for cluster

Aaron Peschel 1 Reputation point
2021-12-20T23:56:46.777+00:00

When I try running aks get-credentials against a specific private cluster, it seems to be adding the wrong hostname to my kube config.

The get-credentials command adds a hostname the privatelink.eastus.azmk8s.io domain, but the cluster's hostname is actually in the hcp.eastus.azmk8s.io domain. If I correct the hostname in the kube config to the correct hostname, I can connect to the cluster fine.

What is going on with the get-credentials command to trigger this behavior?

Additional Info:

The Azure Portal shows a hostname in the hcp.eastus.azmk8s.io which works, but az aks show has the privateFqdn for the cluster in the privatelink.eastus.azmk8s.io domain.

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,218 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Prrudram-MSFT 27,566 Reputation points
    2021-12-22T11:33:59.727+00:00

    Hello @Aaron Peschel ,

    Thank you for reaching Microsoft Q&A Platform. Please find the answer below for your query.

    When you provision a private AKS cluster, AKS by default creates a private FQDN with a private DNS zone and an additional public FQDN with a corresponding A record in Azure public DNS. The agent nodes still use the A record in the private DNS zone to resolve the private IP address of the private endpoint for communication to the API server. Reference

    Thus the primary FQDN for the Private AKS cluster is the private FQDN ( *.privatelink.<region>.azmk8s.io ). The public FQDN ( *.hcp.eastus.azmk8s.io ) is optional and you may choose to disable it. Reference

    The Azure Portal Azure Kubernetes Service Blade is reflects the public FQDN if it is enabled, else it reflects the private FQDN. However, if you run the az aks show command from the Azure CLI you would find both:
    ...
    "fqdn": "akstest-test-xxxxxx-xxxxxxxx.hcp.eastus.azmk8s.io",
    ...
    "privateFqdn": "akstest-test-xxxxxx-xxxxxxxx.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.privatelink.eastus.azmk8s.io",
    ...

    However, az aks get-credentials merges only the primary FQDN (in case of the private AKS cluster, that would be the private FQDN) to the ~/.kube/config file in your local environment.

    Since the private FQDN is not resolvable over public internet hence using that would not help you connect to the private AKS cluster's API server over the internet. However, if you did not disable the public FQDN, then it can be used in the ~/.kube/config file to connect to the private AKS cluster's API server.

    You can also follow the documentation here to access the private AKS cluster remotely.

    1 person found this answer helpful.

  2. Prrudram-MSFT 27,566 Reputation points
    2021-12-24T09:19:46.587+00:00

    Hi @Aaron Peschel ,

    I am glad the information provided has helped you comprehend this scenario. Further to your follow up queries, the private FQDN would not resolve to a public IP address. It resolves to an IP address from the private IP address space of the AKS cluster's VNET/subnet. So unless you are connected to the AKS cluster VNET (through VPN, Expressroute etc.) the connection cannot be made to the API Server using the IP address resolved from the private FQDN.

    Please do not forget to 160325-image.png and 160326-image.png wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.