Kubernetes:拨打 tcp 127.0.0.1:8080:连接:连接被拒绝

Kubernetes : dial tcp 127.0.0.1:8080: connect: connection refused

我已经使用 kops 启动了 kubernetes 集群。它正在工作,我开始面临以下问题:

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

我该如何解决这个问题? 看起来 kubernetes-apiserver 不是 运行,我该如何让它工作?

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

请推荐

Kubernetes 使用 $KUBECONFIG 文件连接到集群。可能是在配置您的 kops 集群时,它没有正确写入文件。我不能确定,因为你没有提供足够的信息。

假设这是问题所在,并且您只有一个集群,可以这样解决:

# 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

您可以找到有关 KUBECONFIG 文件的更多信息 here

您必须先启动 minikube,然后才能使用 kubectl 我有同样的问题,但我的是因为 minikube 不是 运行