15

I've launched kubernetes cluster using kops. It was working find and I started facing the following problem:

kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?

How do i solve this? It looks like kubernetes-apiserver is not running, How do i get this working?

kubectl run nginx --image=nginx:1.10.0
error: failed to discover supported resources: Get http://localhost:8080/apis/apps/v1beta1?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused

Please suggest

prranay
  • 1,789
  • 5
  • 23
  • 33

3 Answers3

12

Kubernetes uses a $KUBECONFIG file for connecting to clusters. It may be when provisioning your kops cluster, it didn't write the file correctly. I can't be sure as you haven't provided enough info.

Assuming this is the issue, and you only have a single cluster, it can be resolved like so:

# Find your cluster name
kops get clusters
# set the clustername as a var
clustername=<clustername>
# export the KUBECONFIG variable, which kubectl uses to find the kubeconfig file
export KUBECONFIG=~/.kube/${clustername}
# download the kubeconfig file locally using kops
kops export kubecfg --name ${clustername} --config=~$KUBECONFIG

You can find more information about the KUBECONFIG file here

jaxxstorm
  • 12,422
  • 5
  • 57
  • 67
3

you have to start minikube before using kubectl I had the same issue but mine was because minikube was not running

0

You can use this command before the kubectl command

gcloud container clusters get-credentials --zone=us-central1

DevAnuragGarg
  • 1,592
  • 2
  • 14
  • 18