Tom Williams
Tom Williams

Reputation: 29

how to set kubectl context

i am trying to create a Kubernetes cluster with the intention of hosting a docker registry, but after installing kubectl (via homebrew on Mac) along with minikube i am getting The connection to the server localhost:8080 was refused - did you specify the right host or port? when i run kubectl version or any other commands. I have previously used the docker desktop app with Kubernetes so don't know if there is any config i need to replace?

I have discovered there is no context set in the kubectl config but if i run kubectl config get-contexts there is nothing there.

Upvotes: 1

Views: 876

Answers (1)

VonC
VonC

Reputation: 1324737

This thread mentions:

That error should only come up if you have no contexts configured in your client.
If you run kubectl config view and you get something like this:

$ kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []

Then no contexts are configured.

And:

Getting kubectl to run really depends on how you installed it.
Basically, if you install and have a proper config file, it should always work.

So, either an old file from a previous installation is there or something silly like that (although usually difficult to spot).

Also, make sure the commands don’t fail (some on the post pasted that the step to copy the kubectl config failed). That is the way to authorize to the cluster, so it won’t never work if that step doesn’t work

Example of possible resolution:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
kubectl get nodes

(From "Creating a cluster with kubeadm")

Upvotes: 2

Related Questions