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

Created on 25 Oct 2018  路  9Comments  路  Source: Azure/azure-cli

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.

AKS question

Most helpful comment

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

All 9 comments

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>

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.

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.

Use:

kubectl config delete-context $cluster

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

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

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

--overwrite-existing worked for me as well!

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

--overwrite-existing worked for me as well!

niceeeeee

Was this page helpful?
0 / 5 - 0 ratings