Description:

Create an alias and enable bash auto-completion for quicker access to kubectl commands



Steps:

1. Install bash-completion if it is not installed

CentOS / Fedora / RHEL:
yum -y install bash-completion

Debian / Ubuntu:
apt-get -y install bash-completion


2. Enable bash completion for "kubectl"

source <(kubectl completion bash)


3. Add bash completion for "kubectl" to .bashrc

echo "source <(kubectl completion bash)" >> ~/.bashrc


4. Set alias "k" for "kubectl" and add bash completion for alias

alias k=kubectl
complete -F __start_kubectl k >> ~/.bashrc


5. Add alias and bash completion to .bashrc to make the changes persistent across sessions

echo "alias k=kubectl" >> ~/.bashrc
echo "complete -F __start_kubectl k" >> ~/.bashrc


6. If you only added the commands to .bashrc make them available in the current session

source ~/.bashrc



Result:

You can now use "k" instead of "kubectl" for kubernetes commands and TAB for auto-completion.