1. Install Bash Completion

source /usr/share/bash-completion/bash_completion

Reload your shell and verify that bash-completion is correctly installed by typing type

_init_completion

2. Enable Kubectl autocompletion

You now need to ensure that the kubectl completion script gets sourced in all your shell sessions. There are two ways in which you can do this:

  • Source the completion script in your ~/.bashrc file:
    echo 'source <(kubectl completion bash)' >>~/.bashrc
    
  • Add the completion script to the /etc/bash_completion.d directory:
    kubectl completion bash >/etc/bash_completion.d/kubectl
    
  • If you have an alias for kubectl, you can extend shell completion to work with that alias:
    echo 'alias k=kubectl' >>~/.bashrc
    echo 'complete -F __start_kubectl k' >>~/.bashrc
    

Source

https://kubernetes.io/docs/tasks/tools/install-kubectl/