minikube stops randomly and can't run kubectl command

9/14/2018

Sometimes when Minikube is already running and I try to run any kubectl command (like kubectl get pods) I get this error:

Unable to connect to the server: dial tcp 192.168.99.101:8443

So I stop Minikube and start it again and all kubectl commands work fine, but then after a while if I try to run any kubectl command I get the same error as above.

If I type minikube ip I get 192.168.99.100. Why does kubectl try to connect to 192.168.99.101 (as mentioned in the error) when Minikube is running on 192.168.99.100?

Note that I'm very new to Kubernetes.

kubectl config get-contexts gives me this output:

CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE
*         minikube   minikube   minikube

This is minikube logs output https://pastebin.com/kb5jNRyW

-- SlimenTN
kubectl
kubernetes
minikube

1 Answer

9/14/2018

This usually happens when the IP of your VM might be changed, and your minikube is pointing to the previous IP, You can check through minikube ip and then check the IP of the VM created, they will be different.

You can also try minikube status, your output will be : minikube: Running cluster: Stopped kubectl: Misconfigured: pointing to stale minikube-vm. To fix the kubectl context, run minikube update-context

You can try minikube update-context and if it doesn't run even then, try minikube start followed by minikube update-context, it won't download everything again, it will only start the VM if shut down.

-- Ali Kahoot
Source: StackOverflow