Saturday, December 19, 2020

Kubernetes for Developers #4: Enable kubectl bash autocompletion

Kubectl provides autocomplete support for bash which can save us lot of typing.

Bash on Windows using Git bash

1. Install Git bash from https://git-scm.com/downloads if it is not available in your computer

2. Navigate to “C:\Users\<yourname>” from Git bash cli

3. Run following command to get kubectl autocompletion bash commands and save into “kubectl-completion.bash” file


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

4. Create or Update .bashrc file source


> echo 'source ~/kubectl-completion.bash' >> .bashrc

5. Restart Git bash and start typing kubectl get po          ( press [TAB] key )














Bash on Windows using Conemu/Cmder

It is an another handy multi and split tab windows terminal. It supports multiple command terminals like cmd, PowerShell, bash and etc.

1. Install Git bash from https://git-scm.com/downloads if it is not available in your computer

2. Install Conemu from https://conemu.github.io/ if it is not available in your computer.

3. Open new Git Bash console from Conemu terminal

4. Navigate to “C:\Users\<yourname>”

5. Run following command to get kubectl autocompletion bash commands and save into “kubectl-completion.bash” file


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

6. Create or Update .bashrc file source


> echo 'source ~/kubectl-completion.bash' >> .bashrc

7. Restart Conemu terminal and start typing kubectl get po   ( press [TAB] key )


Bash on Linux/macOS

Please go through below link to enable kubectl autocompletion on Linux/macOS

https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion


Kubernetes for Developers Journey.
Happy Coding :)

No comments:

Post a Comment