Issue in setting up KUBECTL on Windows 10 Home

4/10/2020

I am trying to learn Kubernetes and so I installed Minikube on my local Windows 10 Home machine and then I tried installing the kubectl. However so far I have been unsuccessful in getting it right. So this what I have done so far: Downloaded the kubectl.exe file from https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/windows/amd64/kubectl.exe

Then I added the path of this exe in the path environment variable as shown below: enter image description here

However this didn't work when I executed kubectl version on the command prompt or even on pwoershell (in admin mode)

Next I tried using the curl command as given in the docs - https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-with-curl-on-windows

However that too didn't work as shown below: enter image description here

Upon searching for answers to fix the issue, I stumbled upon this StackOverfow question which explained how to create a .kube config folder because it didn't exist on my local machine. I followed the instructions, but that too failed.

enter image description here enter image description here

So right now I am completely out of ideas and not sure whats the issue here. FYI, I was able to install everything in a breeze on my Mac, however Windows is just acting crazy.

Any help would be really helpful.

-- Rahul Dev Mishra
kubectl
kubernetes
minikube

1 Answer

4/13/2020

As user @paltaa mentioned:

did you do a minikube start ? – paltaa 2 days ago

The fact that you did not start the minikube is the most probable cause why you are getting this error.


Additionally this error message shows when the minikube is stopped as stopping will change the current-context inside the config file.


There is no need to create a config file inside of a .kube directory as the minikube start will create appropriate files and directories for you automatically.

If you run minikube start command successfully you should get below message at the end of configuration process which will indicate that the kubectl is set for minikube automatically.

Done! kubectl is not configured to use "minikube"

Additionally if you invoke command $ kubectl config you will get more information how kubectl is looking for configuration files:

 The loading order follows these rules:

  1.  If the --kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes
place.
  2.  If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for
your system). These paths are merged. When a value is modified, it is modified in the file that defines the stanza. When
a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the
last file in the list.
  3.  Otherwise, ${HOME}/.kube/config is used and no merging takes place.

Please take a special look on part:

  1. Otherwise, ${HOME}/.kube/config is used

Even if you do not set the KUBECONFIG environment variable kubectl will default to $USER_DIRECTORY (for example C:\Users\yoda\.

If for some reason your cluster is running and files got deleted/corrupted you can:

  • minikube stop
  • minikube start

which will recreate a .kube/config


Steps for running minikube on Windows in this case could be:

  • Download and install Kubernetes.io: Install minikube using an installer executable
  • Download, install and configure a Hypervisor (for example Virtualbox)
  • Download kubectl
    • OPTIONAL: Add the kubectl directory to Windows environment variables
  • Run from command line or powershell from current user: $ minikube start --vm-driver=virtualbox
  • Wait for configuration to finish and invoke command like $ kubectl get nodes.

Please let me know if this helped.

-- Dawid Kruk
Source: StackOverflow