azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

az aks get-credentials error: A different object named {{ name }} already exists in clusters

Open ArseniiPetrovich opened this issue 8 years ago • 9 comments

Describe the bug I have a script that deletes and recreates an AKS cluster. Unfortunately it doesn't work since when I'm trying to recreate cluster and get it creds i receive a following error: A different object named {{ name }} already exists in clusters This error occurs even if I recreate a resource group. I guess Azure stores somehow a name of deleted cluster. How should I properly delete it?

To Reproduce

az group create --name ${cluster}_rg --location $region
az aks create --resource-group ${cluster}_rg --name $cluster --node-count $nodes --enable-addons monitoring --generate-ssh-keys
az aks delete --resource-group ${cluster}_rg --name $cluster
az ad app delete --id http://$cluster
az group delete --name ${cluster}_rg
rm ~/.azure/aksServicePrincipal.json
az group create --name ${cluster}_rg --location $region
az aks create --resource-group ${cluster}_rg --name $cluster --node-count $nodes --enable-addons monitoring --generate-ssh-keys
az aks get-credentials -a --resource-group ${cluster}_rg --name $cluster

Expected behavior I receive valid credentials to use it with the further commands.

Environment summary Azure CLI (2.0.47) installed via apt-get on bash.

ArseniiPetrovich avatar Oct 25 '18 10:10 ArseniiPetrovich

I got around this by editing my kube config (~/.kube/config). Remove the existing cluster, context, and user for the given name. You will then be able to run az aks get-credentials again.

clusters:
- cluster:
    certificate-authority-data: <encoded data>
    server: <url>
  name: <name to delete>

contexts:
- context:
    cluster: <name to delete>
    user: <user to delete>
  name: <name to delete>

users:
- name: <user to delete>
  user:
    client-certificate-data: <encoded data>
    client-key-data: <encoded data>
    token: <hash>

doelleri avatar Oct 29 '18 17:10 doelleri

I went through the same error but it looks like things work anyway. To me it seems like what happens is that the credentials already exist so they won't be retrieved again, so nothing is really going wrong, just the error message is a bit misleading/alarming in this sense.

jperals avatar Nov 01 '18 09:11 jperals

Sorry, I think I read your description too fast: I didn't get that you were trying to delete and recreate a cluster. The issue makes a bit more sense then.

jperals avatar Nov 01 '18 09:11 jperals

Use:

kubectl config delete-context $cluster

nevermind still not working, even after deleting - this is a bug # #

MaurGi avatar Nov 07 '18 20:11 MaurGi

--overwrite-existing flag on the get-credentials should fix it.

viktorpeacock avatar Nov 12 '18 15:11 viktorpeacock

Seems like --overwrite works now. Did the trick for me.

varianone avatar Nov 13 '18 19:11 varianone

--overwrite-existing worked for me as well!

Lroca88 avatar Nov 15 '18 15:11 Lroca88

This question seems to have been answered and is working as intended. Closing.

tjprescott avatar Nov 15 '18 17:11 tjprescott

--overwrite-existing worked for me as well!

niceeeeee

Loetfi avatar May 17 '19 07:05 Loetfi