Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No context found by kubectl when starting cluster with kind create cluster #2174

Closed
hakrac opened this issue Apr 1, 2021 · 11 comments
Closed
Assignees
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@hakrac
Copy link

hakrac commented Apr 1, 2021

After starting the kind cluster with kind create cluster I tried connecting to the cluster with kubectl cluster-info --context kind-kind.
Unfortuntaly kubectl gave me the following error.

error: context "kind-kind" does not exist

Inspecting the contexts available to kubectl I only got my minikube instance.

CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE
*         minikube   minikube   minikube   default

The error persisted even after removing minikube and clearing $HOME/.kube/config.

I am using

Ubuntu 20.04,
kind version 0.10.0,
kubectl client version 1.20.5,
kubectl server version 1.20.2

@hakrac hakrac added the kind/support Categorizes issue or PR as a support question. label Apr 1, 2021
@hakrac
Copy link
Author

hakrac commented Apr 1, 2021

I just found a workaround by appending the output of

sudo kind get kubeconfig

to $HOME/.kube/config.
Shouldn't this happen automatically?

@BenTheElder
Copy link
Member

It should happen automatically. Is your kubeconfig not owned by the current user?

@BenTheElder
Copy link
Member

Also sudo kind export kubeconfig is a less manual way to add it if not, but the fact that it worked with sudo suggests to me that the permissions are wrong on your kubeconfig file, you might need to chown it.

We should print an error / warning if this happens as well, if kind doesn't that's a bug in itself though we still need you to correct the permissions on the file or specify a different file to use.

@BenTheElder BenTheElder self-assigned this Apr 1, 2021
@hakrac
Copy link
Author

hakrac commented Apr 1, 2021

In my case $HOME/.kube/config is owned by the currenty active user who has read as well as write permisson.

@BenTheElder
Copy link
Member

What about the directory?

@BenTheElder
Copy link
Member

Are there any stray lock files?

@hakrac
Copy link
Author

hakrac commented Apr 1, 2021

My .kube directory is owned by the active user.

I am currently executing all docker related commands as root user so this should not be the problem.

@BenTheElder
Copy link
Member

I am currently executing all docker related commands as root user so this should not be the problem.

Ah, that explains it.

kubernetes has rules about where kubeconfig is written, it will default to under the current user.

if you run kind as root, it will likely write the kubeconfig under the root user's homedir then. we use the same lookup logic as kubectl. most likely there is a kubeconfig under the root's homedir with the kind configuration.

@BenTheElder
Copy link
Member

BenTheElder commented Apr 1, 2021

you can do one of:

  • add this kubeconfig to KUBECONFIG (which supports a list in all kubernetes tools following the spec)
  • use --kubeconfig when calling kind or kubectl (and possibly chown after calling kind if you go that route)
  • run kubectl as the same user as kind
  • merge the kubeconfig with the kubeconfig under your user with KUBECONFIG="${ROOT_HOME}/.kube/config:~/.kube/config kubectl" config view --flatten >~/.kube/config (replace ${ROOT_HOME} with the root homedir)

@hakrac
Copy link
Author

hakrac commented Apr 1, 2021

I solved the issue by adding my user to the docker group (to run docker without root privileges) and running kind create cluster.
Thanks;

@hakrac hakrac closed this as completed Apr 1, 2021
@SmadusankaB
Copy link

kubectl config set-context kind-kind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

3 participants