Reputation: 2173
I have KUBECONFIG inside my .kube/ folder still facing this issue.
I have also tried
kubectl config set-context ~/.kube/kubeconfig.yml
kubectl config use-context ~/.kube/kubeconfig.yml
No luck! Still the same.
Upvotes: 6
Views: 46806
Reputation: 409
if u are running k3s u can put the following line to ur ~/.zshrc / ~/.bashrc
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
Upvotes: 3
Reputation: 51
I had the same problem because I used the Linux subsystem on Windows.
If you use the command kubectl
in the subsystem, you must copy your config file to part of the Linux system.
For example, if your username on Windows is jammy, and your username is also jammy in the Linux subsystem, you must copy the config file from: /mnt/c/Users/jammy/.kube/config to: /home/jammy/.kube/
Upvotes: 1
Reputation: 2173
Answering my own question
Initially, I had lost a lot of time on this error, but later I found that my kubeconfig is not having the correct context.
I tried the same steps:
kubectl config set-context ~/.kube/kubeconfig1.yml
kubectl config use-context ~/.kube/kubeconfig1.yml
or add a line with kubeconfig to your ~/.bashrc
file
export KUBECONFIG=~/.kube/<kubeconfig_env>.yml
Also, if you want to add multiple kubeconfig: Add it like in ~/.bashrc
file
export KUBECONFIG=~/.kube/kubeconfig_dev.yml:~/.kube/kubeconfig_dev1.yml:~/.kube/kubeconfig_dev2.yml
with different Kube contexts and it worked well.
Though the error should simplify and return the specific error related to kubecontext.
But after some digging it worked.
Upvotes: 7