How to Set an Alias for ‘kubectl’ to ‘k’ in Linux

An alias is a user-defined shortcut for a longer command or sequence of commands. It is essentially a custom nickname you can assign to a specific action or utility

Step 1: Check for Existing Aliases

Before creating a new alias, it’s essential to check if the alias ‘k’ is already in use or if it conflicts with any existing commands

alias | grep k=

Step 2: Edit Your Shell Configuration File

Aliases are usually defined in your shell’s configuration file, in case edit via vi

vi .bashrc

Step 3: Add the Alias

In your shell configuration file, add the following line

alias k='kubectl'

This line assigns the alias ‘k’ to the kubectl command

Step 4: Save and Apply the Changes

After adding the alias, save the changes and close the text editor

source .bashrc

Step 5: Test the Alias

Now that you have set up the alias

k get pods

If everything was configured correctly, the output should be the same as if you had typed kubectl get pods