Search code examples
azurekuberneteskubectlazure-powershell

Unable to connect to the server: getting credentials: exec: executable kubelogin not found


I created new config file for Kubernetes from Azure in Powershell by az aks get-credentials --resource-group <RGName> --name <ClusterName>. Got a message that Merged "cluster_name" as current context in C:\michu\.kube\config. I copied this file into default .kube\config location and now when I try to run any command e.g kubectl get pods I am receiving:

Unable to connect to the server: getting credentials: exec: executable kubelogin not found

It looks like you are trying to use a client-go credential plugin that is not installed.

To learn more about this feature, consult the documentation available at:
      https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins

What is wrong here?

I just realized that when I type kubectl config get-contexts then I can see my cluster_name and I can even switch to this by kubectl config use-context cluster_name and message is correct: Switched to context cluster_name but then still all other commands ends with Unable to connect to the server: getting credentilas: exec: executable kubelogin not found


Solution

  • The error implies that the kubelogin executable could not be located. You need to install kubelogin in the azure cli using az aks install-cli, then it works as expected.

    Refer github for installation process.

    I tried the same requirement in my environment, and it worked for me as follows.

    az aks get-credentials --resource-group caroline --name sampleaks1
    kubectl get pods
    

    Output:

    enter image description here

    Once you have the aks credentials, running kubectl get pods will prompt you for an Azure kubernetes service authentication with AAD, as shown.

    enter image description here

    Just give kubectl in the bash to verify whether it is installed successfully.

    enter image description here

    If still the issue persists,

    1. Delete all the cache or any unused folders inside the ~/.kube/ and ran the aks credentials command by adding --admin flag in the end.

      Refer this doc by @Geert Baeke for more related information.

    2. Check the kube config version and upgrade if required.