Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl bash completion doesn't work in ubuntu docker container

I'm using kubectl from within a docker container running on a Mac. I've already successfully configured the bash completion for kubectl to work on the Mac, however, it doesn't work within the docker container. I always get bash: _get_comp_words_by_ref: command not found.

The docker image is based on ubuntu:16.04 and kubectl is installed via the line (snippet from the dockerfile)

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
mv kubectl /usr/local/bin

echo $BASH_VERSION gives me 4.3.48(1)-release, and according to apt, the bash-completionpackage is installed.

I'm using iTerm2 as terminal.

Any idea why it doesn't work or how to get it to work?

like image 642
DonGiovanni Avatar asked May 18 '18 07:05

DonGiovanni


People also ask

How do you use kubectl autocomplete?

To use shell autocompletion with kubectl simply press tab while writing out a command. For example we can type g and then press tab to autocomplete to get . When we type s you may expect pressing tab would autocomplete to service, but in this case there are more than a few options for words starting with s .

How do I know if bash completion is installed?

If the autocomplete results contain directories only (no files), then Bash Completion is installed. If the autocomplete results include files, then Bash Completion is not installed.


1 Answers

Ok, I found it - I simply needed to do a source /etc/bash_completion before or after the source <(kubectl completion bash).

like image 133
DonGiovanni Avatar answered Oct 08 '22 14:10

DonGiovanni