按《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

[sunwa@sunwa-centos .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切回来

[sunwa@sunwa-centos ~]$ k config use-context gke_firstk-k8s-project_asia-east2-a_kubia
Switched to context "gke_firstk-k8s-project_asia-east2-a_kubia".

之后就可以啦

[sunwa@sunwa-centos ~]$ 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
Logo

开源、云原生的融合云平台

更多推荐