Hi all,
I am just getting started with Kubernetes and the kubectl
command specifically.
As there are so many flags and arguments, is there a way to enable autocompletion just like in git
?
So for example when I type kubectl get no[TAB]
it would autocomplete nodes
.
Thank you!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
Yes, this is doable. What you would need to do is to first to make sure that you have the
bash-completion
package installed. If not, you could install it with the following command:After that, you could generate the required
kubectl
completion rules with thekubectl completion bash
command, and then store the rules in your.bashrc
file. You could use the following command to do that:After that, use the
source
command to activate the new rules:Finally, if you were not now run
kubectl get no[TAB]
it will be autocompleted.This is indeed quite handy! Hope that this helps. Regards, Bobby
I would look at this page https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-autocomplete
Essentially for:
Bash
You could use it for aliases as I usually use
k
instead of the fullkubectl
command it is usefullZSH