我已经使用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的更多信息