kubectl使用minikube后报错The connection to the server localhost:8080 was refused
程序员文章站
2024-03-14 13:28:58
...
按《Kubernetes in action》入门,在使用minikube start后,再执行minikube stop就会出现如下问题
$ kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?
这个明显是配置错误,但是确认~/.kube/config没有问题。后来发现是因为minikube start的时候,将kubectl的context切换了,但在minikube stop的时候,没有将context切换回来
$ kubectl config current-context
error: current-context is not set
可以先看一下自己已有哪些context
[[email protected] .kube]$ k config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
gke_firstk-k8s-project_asia-east2-a_kubia gke_firstk-k8s-project_asia-east2-a_kubia gke_firstk-k8s-project_asia-east2-a_kubia
然后再把context切回来
[[email protected] ~]$ k config use-context gke_firstk-k8s-project_asia-east2-a_kubia
Switched to context "gke_firstk-k8s-project_asia-east2-a_kubia".
之后就可以啦
[[email protected] ~]$ k get pods
NAME READY STATUS RESTARTS AGE
kubia-52wsg 1/1 Running 0 108m
kubia-b4hkw 1/1 Running 0 77m
kubia-xfff5 1/1 Running 0 77m