How to enable bash auto-completion with kubectl on Ubuntu

The kubectl fruition content for Bash can be produced with the order kubectl fulfillment slam. Sourcing the fulfillment content in your shell empowers kubectl auto-completion.

 

In this post, We will configure kubectl auto completion on ubuntu.


Step 1: Install bash-completion Package

You need to install the bash-completion packages by using the given command.
 

$ sudo apt-get install bash-completion -y

 In my case, It is already installed.

 

Step 2: Get Shell Name

 

Execute the below the command to get the shell name.

 

$ echo "$SHELL"

 

Step 3: Configuration of Source

 

You need to execute the given command and create a bash file inside .kube directory, Follow the below step one by one.

$ kubectl completion bash 


You should get output like this.

Now you need to create a kubectlcommand.sh file inside .kube diretory by following the below command.


$ kubectl completion bash > .kube/kubectlcommand.sh

Lets verify the created file in .kube directory.

 

 

Its time source the given command in .profile file in your home diretory So that whenver you are login in your username that command will exeute and kubectl auto completion will work.

source $HOME/.kube/.kube/kubectlcommand.sh

Its time source the given command in .profile file in your home diretory So that whenver you are login in your username that command will exeute and kubectl auto completion will work.

$ sudo vim .profile

Add the given syntax like this.

source $HOME/.kube/.kube/kubectlcommand.sh


 

Save and exit from the vim editor, To get changes you need to logout and login again in your linux machine.

 

Step 4: Testing Kubectl Auto completion

 

As can seen kubectl auto completion working fine.

 

 

 

Conclusion

In this post, We have success install and configure kubectl bash autocompletion on ubuntu, Still have any issue, Please leave a comment.

 

 

 

How to enable bash auto-completion with kubectl on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top