Search code examples
kubectlazure-aksazure-cli

How to make kubectl not use AZURE_CLIENT_ID environment variable?


I have AZURE_CLIENT_ID environment variable set up on my machine. I have noticed that recently when I run my kubectl commands, it requires authentication and tries to do it with the value from that environment variable.

I want it to ignore this value as I think it always did before, so it is something new with the latest kubectl or the version that is installed via az.

The cluster is deployed in AKS.


Solution

  • There are few ways to avoid using the existed AZURE_CLIENT_ID environment variable to make kubectl works with the other user login authentication.

    Approach-1:

    You can unset the environment variable if it is not required for some period. Use below AZ cli command to unset.

    unset AZURE_CLIENT_ID
    

    enter image description here

    Approach-2:

    As detailed in kubectl github documentation, you can set the required user credentials and login with kubectl, with the below AZ cli command as shown.

    I provided --auth-provider-arg for the client_id as an empty string to ignore the existed environment variable. You can modify the value as per the requirement.

    Here, I tried to set the credentials for a user named Jahnavi with an empty client-id value and the user was successfully set as follows:

    kubectl config set-credentials <jahnavi> --auth-provider=azure --auth-provider-arg=environment=AzurePublicCloud 
    --auth-provider-arg=CLIENT_ID=  --auth-provider-arg=tenant-id="tenantID"
    

    enter image description here

    Approach-3:

    If still the issue persists, you can directly view the config file and edit the user credentials by executing kubectl config view command.

    It will display the Kubernetes configuration file contents, as well as the file's path. After that, you can update the file to remove the Azure credentials accordingly.

    kubectl config view
    

    enter image description here

    You can also refer this document for more related information.