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

prr*_*nay 6 kubernetes devops kubectl kops

我已经使用kops启动了kubernetes集群。查找工作正常,我开始遇到以下问题:

kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Run Code Online (Sandbox Code Playgroud)

我该如何解决?看来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
Run Code Online (Sandbox Code Playgroud)

请建议

jax*_*orm 7

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
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到有关该KUBECONFIG文件的更多信息