Kubernetes - kubectl version command fails

6/3/2019

Ubuntu 19.4

Just installed kubectl via snap: https://kubernetes.io/docs/tasks/tools/install-kubectl/

lky@lky-Z170-D3H:~$ kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?

Any ideas what could cause it?

-- Ɓukasz
kubectl
kubernetes

2 Answers

6/3/2019

it means that kubectl client version that you have installed is v1.14.2.

you cant connect to api server due to some issue, and hence kubernetes server version is not shown.

run below command to check kubernetes control plane health and take action on the components that are shown as UnHealthy

kubectl get cs
-- P Ekambaram
Source: StackOverflow

6/4/2019

After installing kubectl, you have to configure it to use your cluster. Almost any cloud providers, or bootstrappers such as kubeadm has easiest way to do it. For example, on GKE you run below command to copy your cluster k8s config file, to localhost:

gcloud container clusters get-credentials ${CLUSTER}

For Kops:

kops export kubecfg ${CLUSTER}

For kubeadm you have to copy config file from master to your host machine. After completing kubeadm init command:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Note: /etc/kubernetes/admin.conf is located in master kubeadm node where you run kubeadm init, and you must copy this file to your host machine to use this cluster with kubectl.

Other useful links can be helpful:

Accessing first time with kubectl Configure Access to Multiple Clusters

Hope it helps!

-- coolinuxoid
Source: StackOverflow