Search code examples
kuberneteskubectlmicrok8s

kubectl keeps asking for login every command


What happened: We're on AKS with RBAC enabled. Executing any kubectl/helm command that connects to the k8s cluster, I have to reauthenticate. Output:

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXX to authenticate. This succeeds but then when I execute the next kubectl command I have to reauthenticate again.

What you expected to happen: Authenticate and use that token for more than one command.

How to reproduce it (as minimally and precisely as possible):

Get credentials and then execute any kubectl command.

Anything else we need to know?:

Environment:

Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e199641833566e5d052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}

On one of the git answer (https://github.com/Azure/AKS/issues/1057), I found that we have to remove config.lock to resolve the issue, but there is no such file in my case. Help appreciated !


Solution

  • I recommend using az login An auth token is cached locally on your environment and should give you access to your Kubernetes cluster.

    Then follow the Microsoft docs to install kubectl.

    az aks install-cli
    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster