Use kubectl completion <shell> to install tab completion for your shell of choice. For the examples below, we will be installing bash completion on Ubuntu 16.04 LTS.

Single-User

To enable bash completion for a single user, run the following command, and then logout and log back into your shell.

cat > $HOME/.bash_profile << __EOF__
source <(kubectl completion bash)
__EOF__

All Users

To enable bash completion for all users, run the following command, and then logout and log back into your shell.

cat > /etc/bash_completion.d/kubectl << __EOF__
source <(kubectl completion bash)
__EOF__

Testing it Out

# Simplest case: completing kubectl commands
ubuntu@jupytest-master:~$ kubectl <TAB>
alpha          api-versions   auth           cluster-info   convert        create         drain          explain        label          patch          proxy          run            taint          version        
annotate       apply          autoscale      completion     cordon         delete         edit           expose         logs           plugin         replace        scale          top            wait           
api-resources  attach         certificate    config         cp             describe       exec           get            options        port-forward   rollout        set            uncordon   


# Completing resource names:
ubuntu@jupytest-master:~$ kubectl get ns <TAB>
admin        bindtest     default      jupytest     kube-public  kube-system  support      workbench 


# Build up complex commands very quickly using TAB complete:
ubuntu@jupytest-master:~$ kubectl logs -f -n <TAB>
admin        bindtest     default      jupytest     kube-public  kube-system  support      workbench    
ubuntu@jupytest-master:~$ kubectl logs -f -n workbench <TAB>
ubuntu@jupytest-master:~$ kubectl logs -f -n workbench ndslabs-workbench-5f9df8cdbb-vjqv6
ubuntu@jupytest-master:~$ kubectl logs -f -n workbench ndslabs-workbench-5f9df8cdbb-vjqv6 -c <TAB>
apiserver  etcd       smtp       webui  

  • No labels