Open lbruun opened 1 year ago
Thank you for opening this issue, we will look into it.
I got this error when I had an almost empty ~/.kube/config
file (I assume kind
created it) when I tried to run az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
. Deleting the file and rerunning the az
command solved it.
I've found this: https://kubernetes.io/docs/reference/config-api/kubeconfig.v1/
This indicates that the clusters
property is indeed mandatory. So having a kubeconfig file without it would constitute an invalid kubeconfig file. If this is correctly understood it means that it is Kind which is doing something wrong and the problem should probably be reported in the their issue tracker.
For anyone in need. Here's a workaround that works with yq v4.44.3:
yq eval '.clusters = .clusters // [] | .users = .users // [] | .contexts = .contexts // []' -i ~/.kube/config
Related command
az aks get-credentials
Describe the bug
The
az aks get-credentials
command incorrectly expects that the local kube config file must have aclusters
key in order to be valid.This kube config will work with the az command:
while this will not:
and produces error message:
Other tools in the Kubernetes ecosystem do not behave like this when parsing the kube config file. This is specifically a problem in CI pipelines for example together with
kind
. See reproduction below.To Reproduce
rm -r -f ~/.kube/config
(This removes local kube config and thereby simulates that we start out fresh, just like a CI pipeline would do.)kind create cluster
kind delete cluster
az aks get-credentials .....
results in error:Expected behavior
That
az aks get-credentials .....
would parse the kube config file similarly to other tools in the Kubernetes ecosystem, in particular those from the Kubernetes project itself (cough: kind).Current workaround
In a CI pipeline you'll need to completely remove the kube config file (
rm -r -f ~/.kube/config
) after having usedkind
(or any other tool which may manipulate the kube config file). This will make theaz aks get-credentials
command work.