minikube: Tab completion breaks if using recommended alias kubectl='minikube kubectl --'

  1. install minkube
  2. add alias kubectl=‘minikube kubectl --’ to .bashrc
  3. add source <(kubectl completion bash) to .bashrc

result: only the commands get tab-completed, nothing after that.

the underlying issue is this:

$ minikube kubectl __completeNoDesc get p
Error: flags cannot be placed before plugin name: --cluster

this works however:

~/.minikube/cache/linux/v1.22.3/kubectl __completeNoDesc get p

related to this: https://github.com/kubernetes/kubectl/issues/884

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

just realized that my hack doesnt work if the minikube node is down… because of reasons.

this does work however:

KUBECTL_PATH="$HOME/.minikube/cache/linux/$(minikube kubectl -- version 2>/dev/null | perl -lne '/GitVersion:"([^"]*)"/ && print $1')/kubectl"

it’s even worse though.

found this workaround. put it in bashrc:

KUBECTL_PATH="$HOME/.minikube/cache/linux/$(minikube kubectl -- version -o json | jq -r '.clientVersion.gitVersion')/kubectl"

kubectl() {
    $KUBECTL_PATH "$@"
}

source <(kubectl completion bash)