'error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

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.



Solution 1:[1]

By default, kubectl looks for a file named config in the $HOME/. kube directory. So you have to rename your config file or set its location properly.

Look here for more detailed explanation

Solution 2:[2]

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/

Solution 3:[3]

if u are running k3s u can put the following line to ur ~/.zshrc / ~/.bashrc

k3s

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 m303945
Solution 2 Ognjen Stanisavljevic
Solution 3 Alpha