Search code examples
azurekubernetesazure-devopsazure-aks

executable kubelogin failed with exit code 1


I'm using an Kubernetes server with API version (1.25.2) . When I try to do a kubectl command getting the below error

TRONBQQ2:~$ kubectl get nodes
error: unknown flag: --environment
error: unknown flag: --environment
error: unknown flag: --environment
error: unknown flag: --environment
error: unknown flag: --environment
Unable to connect to the server: getting credentials: exec: executable kubelogin failed with exit code 1

From the same terminal I'm able to access the Kubernetes server with version 1.23.12.

Is this due to an old kubectl clieint version?.

TRONBQQ2:~$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", 
BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
TRONBQQ2:~$ sudo apt-get install -y kubectl
Reading package lists... Done
Building dependency tree
Reading state information... Done

kubectl is already the newest version (1.19.4-00). 0 upgraded, 0 newly installed, 0 to remove and 313 not upgraded.

I even tried to upgrade the kubectl . Even after upgrade, version remains in v1.19.4. Not sure this is the reason for the above mentioned error


Solution

  • Try to check whether the the following command is printing the below options.

    >>>kubelogin -h
    
    Login to azure active directory and populate kubeconfig with AAD tokens
    
    Usage:
      kubelogin [flags]
      kubelogin [command]
    
    Available Commands:
        completion         Generate the autocompletion script for the specified shell
       convert-kubeconfig convert kubeconfig to use exec auth module
       get-token          get AAD token
      help               Help about any command
      remove-tokens      Remove all cached tokens from filesystem
    
     Flags:
         -h, --help          help for kubelogin
         --logtostderr   log to standard error instead of files (default true)
     -v, --v Level       number for the log level verbosity
      --version       version for kubelogin
    

    It seems I was having a different kubelogin and missed the above specified Command Options. So I installed the new version of kubelogin using

     az aks install-cli
    

    If that doesn't work, then you can refer "enter image description here" to get the kubelogin brew package

    Also export the below path

    export PATH="/usr/local/bin:$PATH"
    

    Once the kubelogin is available , run the below command to convert your KUBECONFIG

    kubelogin convert-kubeconfig --kubeconfig ./kube/config