Boost Your Productivity with Kubectl Auto-Completion!

Boost Your Productivity with Kubectl Auto-Completion!

With Kubectl, you might often search online for command examples and help pages. But did you know Kubectl has built-in features to assist you? If you're on Linux using the bash shell, you can enable auto-completion right in your terminal.

Install Kubectl Completion Script

To enable autocompletion for the current session, run:

source <(kubectl completion bash)        

Persist Autocompletion

Make this change permanent by adding it to your .bashrc or .bash_profile file:

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

or

echo 'source <(kubectl completion bash)' >> ~/.bash_profile        

Then, apply the changes by sourcing the file

source ~/.bashrc        

or

source ~/.bash_profile        

Enable Autocompletion for Aliased Commands

If you use an alias for kubectl (e.g., alias k=kubectl), enable autocompletion for the alias as well:

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


Now, just press Tab to auto-complete commands or Tab twice to list available commands and options. It's a great way to save time and avoid typos—especially helpful if you're prepping for a Kubernetes certification exam.

For example, type "kubectl" and press Tab twice to see all available commands. Start typing "g" and hit Tab to auto-complete "get," your go-to for displaying resources. Need to see all nodes? Just type "get nodes" and press Enter.

Happy kubectl-ing! 🎉

#Kubernetes #kubectl #ProductivityHacks #Linux #DevOps #TechTips

To view or add a comment, sign in

More articles by Akhilesh Mishra

Insights from the community

Others also viewed

Explore topics