skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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 ./kube/config
    

  2. I tried to reproduce the same issue in my environment and got the below results

    I did the following issue to resolve the issue

    This issue will occur due to the version, we have to upgrade the latest version

    I have set the subscription id to AKS cluster using below command

    az account set --subscription "subscription_id"
    az aks get-credentials --resource-group <rg-name> --name <cluster-name> --admin
    

    enter image description here

    My current AKS version is 1.23.12

    enter image description here

    My Kubectl version is

    kubectl version --client
    

    enter image description here

    This error will occur based on the kube/config file and the config file should be exist

    cd ~/.kube/.
    vi config
    

    I have the config file configured we won’t get any error

    Below is my config file

    apiVersion: v1
        clusters:
        - cluster:
            certificate-authority-data: XXXXXXXXX
            server: https:cluster123.hcp.azmk8s.io.443
          name: cluster123
        contexts:
        - context:
            cluster: cluster123
            user: clusterUser_Alldemorg_cluster123
          name: komali-test
        current-context: cluster123
        kind: Config
        preferences: {}
            client-certificate: XXXXXX
            client-key-Data: XXXXXXX
    

    I have followed the below commands to access the kubectl commands

    kubelogin convert-kubeconfig -l azurecli
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search