Command completion for minikube and kubectl on Windows 10

The minikube and kubectl commands both support command completion for bash and zsh shells. Windows 10 now supports bash. When I actually tried to use minkube and kubectl command completions in bash, it worked, but the commands failed to execute. I even had the minikube and kubectl commands in the PATH. What gives?

> # Let us try completion...
> mini<TAB>
> minikube stat<TAB>
> minikube status
No command 'minikube' found, did you mean:
Command 'minitube' from package 'minitube' (universe)
minikube: command not found
> # Command completion works but, command does not run. What gives?
> which minkube
> # ^ no ouput
> which minikube.exe
/mnt/c/Program Files (x86)/Kubernetes/Minikube/minikube.exe
> # ^ Good. Ah, that gives us a clue.

It turns out, unlike cmd or powershell, bash does not automatically append .exe extention (argh!). But for the command completion to work we have to use the minikube and kubectl (without the .exe extention).

bash alias to the rescue. Simply add the following two aliases to your .bashrc:

alias minikube='minikube.exe'
alias kubectl='kubectl.exe'

Let us try it now:

> minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.1.31
> kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
kube-addon-manager-minikube 1/1 Running 0 5d
kube-dns-86f6f55dd5-7rgdr 3/3 Running 3 12h
kubernetes-dashboard-6wgzs 1/1 Running 1 12h

Ah, much better. Enjoy command completions in bash shell on Windows 10.

TIP: To set up the command completion do the following:

> minikube.exe completion bash > ~/minikube-completion.bash
> kubectl.exe completion bash > ~/kubectl-completion.bash

and then source in those files in .bashrc like so:

source ~/minikube-completion.bash
source ~/kubectl-completion.bash
alias minikube='minikube.exe'
alias kubectl='kubectl.exe'

TIP: If you want to work with docker command you can add the following to .bashrc:

eval $(minikube docker-env --shell bash)
alias docker='docker.exe -H $DOCKER_HOST --tlsverify'

For some reason the environment variables actually do not get picked up by docker command. For that reason I had to set use the -H and --tlsverify flags in the alias. I also had to copy all the .pem files in C:\\Users\\\\.minikube\\certs\\** to C:\\Users\\\\.docker folder.

Now let us verify that we can use docker command:

> docker images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gcr.io/google_containers/kubernetes-dashboard-amd64 v1.8.0 55dbc28356f2 5 weeks ago 119MB
gcr.io/google_containers/k8s-dns-sidecar-amd64 1.14.5 fed89e8b4248 3 months ago 41.8MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64 1.14.5 512cd7425a73 3 months ago 49.4MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 1.14.5 459944ce8cc4 3 months ago 41.4MB
gcr.io/google-containers/kube-addon-manager v6.4-beta.2 0a951668696f 6 months ago 79.2MB
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 20 months ago 747kB

TIP: The minikube and kubectl commands only seem to work when I run bash as Adminstrator.