Rajat jain
Rajat jain

Reputation: 2173

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.

Upvotes: 6

Views: 46806

Answers (4)

Alpha
Alpha

Reputation: 409

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

k3s

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

Upvotes: 3

Ognjen Stanisavljevic
Ognjen Stanisavljevic

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

Rajat jain
Rajat jain

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

Tarum
Tarum

Reputation: 993

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

Upvotes: 1

Related Questions