If you’re working with Kubernetes, you’ve probably found yourself typing long commands like kubectl get pods or kubectl logs my-pod --follow --tail=50 over and over again. It gets tedious quickly, right?

Good news! Starting with Kubernetes version 1.33, there’s now a built-in way to create shortcuts (called “aliases”) for these repetitive commands. It’s called kuberc, and in this guide, I’ll walk you through everything you need to know to set it up and start saving time.

What You’ll Learn

By the end of this tutorial, you’ll know how to:

  • Install the right version of kubectl
  • Enable the kuberc feature on your computer
  • Create your own command shortcuts
  • Use and test these shortcuts
  • Troubleshoot common issues

Why Should You Care About Aliases?

Think of aliases like speed dial for your phone. Instead of typing out a full phone number every time, you just press one button.

Similarly, instead of typing:

1
kubectl get pods --namespace=production --output=yaml

You could just type:

1
kgp

Much easier, right? This saves time, reduces typos, and makes your work more efficient.

What’s New About Kuberc?

The Old Way (Before Kubernetes 1.33)

Previously, if you wanted shortcuts for kubectl commands, you had to manually add them to your shell configuration files (like .bashrc or .zshrc). This meant mixing Kubernetes shortcuts with all your other shell settings, making things messy and hard to manage.

The New Way (Kubernetes 1.33+)

Now, kubectl has its own dedicated configuration file called kuberc. It’s a clean, organized YAML file specifically for kubectl aliases. This keeps your shortcuts separate from other configurations and makes them easier to manage and share with your team.

Step 1: Check and Upgrade Your Kubectl Version

First things first - you need kubectl version 1.33 or higher for this to work.

Check Your Current Version

Open your terminal and run:

1
kubectl version --client

You should see something like:

1
2
Client Version: v1.33.1
Kustomize Version: v5.6.0

Look at the number after “Client Version: v” - if it’s 1.33 or higher, you’re good to go! If it’s lower (like v1.28 or v1.30), you need to upgrade.

How to Upgrade Kubectl

Visit the official kubectl installation documentation and follow the instructions for your operating system:

  • Linux users: Follow the Linux installation guide
  • Mac users: You can use Homebrew with brew upgrade kubectl
  • Windows users: Follow the Windows installation guide

After upgrading, check the version again to confirm it worked.

Step 2: Enable the Kuberc Feature

Even though you now have the right version, the kuberc feature isn’t turned on automatically. You need to enable it manually.

Turn On Kuberc

Run this command in your terminal:

1
export KUBECTL_KUBERC=true

This tells kubectl: “Hey, I want to use the kuberc file for my aliases!”

Make It Permanent

Important: The command above only works for your current terminal session. If you close the terminal and open a new one, you’ll need to run it again.

To make it permanent, add this line to your shell configuration file:

For Bash users (most Linux distributions):

1
echo 'export KUBECTL_KUBERC=true' >> ~/.bashrc

For Zsh users (default on newer Macs):

1
echo 'export KUBECTL_KUBERC=true' >> ~/.zshrc

After adding this, close and reopen your terminal, or run source ~/.bashrc (or source ~/.zshrc for Zsh) to apply the changes immediately.

Step 3: Understanding the Kuberc File Location

Default Location

By default, kubectl looks for your kuberc file at:

1
~/.kube/kuberc

Let me break this down:

  • ~ means your home directory (like /home/username on Linux or /Users/username on Mac)
  • .kube is a hidden folder where kubectl stores its configuration
  • kuberc is the file where you’ll define your aliases

Using a Custom Location (Optional)

If you want to use a different location for your kuberc file, you can! Just use the --kuberc flag whenever you run kubectl commands:

1
kubectl --kuberc /path/to/my/custom/kuberc get pods

Why would you use this? Maybe you have different aliases for different projects or environments (development, staging, production). You could create separate kuberc files for each and switch between them easily.

Step 4: Create Your Kuberc File

Now let’s create the actual configuration file where you’ll define your shortcuts.

Create the File

Run this command:

1
vim ~/.kube/kuberc

Don’t like vim? You can use any text editor you prefer:

1
2
3
nano ~/.kube/kuberc
# or
code ~/.kube/kuberc # if you have VS Code installed

Step 5: Understanding the Kuberc Configuration Structure

The kuberc file is written in YAML format (the same format used for Kubernetes configuration files). Here’s what a basic kuberc file looks like:

1
2
3
4
5
6
7
apiVersion: kubectl.config.k8s.io/v1beta1
kind: Preference
aliases:
- name: kgp
command: get
appendArgs:
- pods

Breaking Down the Structure

Line 1: apiVersion: kubectl.config.k8s.io/v1beta1

  • This tells kubectl which version of the kuberc format you’re using
  • Since this is still a beta feature, it uses “v1beta1”

Line 2: kind: Preference

  • This indicates that this file contains user preferences for kubectl
  • Think of it like a label that says “this is a preferences file”

Line 3: aliases:

  • This is where your actual shortcuts are defined
  • Everything under this is a list of aliases you want to create

The Alias Definition:

  • name: The shortcut you’ll type (like kgp)
  • command: The kubectl command to run (like get)
  • appendArgs: Additional arguments or options (like pods)

When you type kubectl kgp, it automatically expands to kubectl get pods.

Step 6: Creating Your First Aliases

Let’s create some useful aliases! Add this configuration to your kuberc file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
apiVersion: kubectl.config.k8s.io/v1beta1
kind: Preference
aliases:
# Get all pods quickly
- name: kgp
command: get
appendArgs:
- pods

# Watch pod logs with recent history
- name: klogs
command: logs
appendArgs:
- --follow
- --tail=50

# Create a new namespace
- name: crns
command: create namespace
appendArgs:
- dev-project-01

# Get all deployments
- name: kgd
command: get
appendArgs:
- deployments

# Get all services
- name: kgs
command: get
appendArgs:
- services

What Each Alias Does

  1. kgp - Quickly view all pods in the current namespace

    • Instead of: kubectl get pods
    • You type: kubectl kgp
  2. klogs - View live logs from a pod, showing the last 50 lines

    • Instead of: kubectl logs my-pod --follow --tail=50
    • You type: kubectl klogs my-pod
  3. crns - Create a namespace called “dev-project-01”

    • Instead of: kubectl create namespace dev-project-01
    • You type: kubectl crns
  4. kgd - View all deployments

    • Instead of: kubectl get deployments
    • You type: kubectl kgd
  5. kgs - View all services

    • Instead of: kubectl get services
    • You type: kubectl kgs

Step 7: Advanced Feature - Overrides

Overrides let you set default flags for certain commands. This is super useful for commands you always want to run with specific options.

What Are Overrides?

Imagine you always want to see pod information in YAML format, or you always want a confirmation before deleting something. Overrides let you set these defaults automatically.

Example Override Configuration

Add this to your kuberc file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apiVersion: kubectl.config.k8s.io/v1beta1
kind: Preference
aliases:
- name: kgp
command: get
appendArgs:
- pods

overrides:
# Always get output in YAML format
- command: get
flags:
- name: output
default: "yaml"

# Always ask for confirmation before deleting
- command: delete
flags:
- name: interactive
default: "true"

# Apply changes server-side by default
- command: apply
flags:
- name: server-side
default: "true"

# Automatically add -it flags to exec commands
- command: exec
flags:
- name: it

Understanding Each Override

1. Get Command Override (output: yaml):

  • When you run kubectl get pods, it automatically adds -o yaml
  • You’ll see full YAML output instead of the simple table format
  • Great for when you need detailed information

2. Delete Command Override (interactive: true):

  • Before deleting anything, kubectl will ask: “Are you sure?”
  • Prevents accidental deletions (we’ve all been there!)
  • You can confirm or cancel before anything is deleted

3. Apply Command Override (server-side: true):

  • Tells kubectl to process changes on the server side
  • More efficient for large configurations
  • Reduces network traffic

4. Exec Command Override (it flag):

  • Automatically adds -it when you run exec commands
  • -i = interactive (keeps stdin open)
  • -t = allocates a terminal
  • Essential for running shell commands in containers

Step 8: Testing Your Aliases

Now that you’ve set everything up, let’s test it!

Test 1: View Pods

1
kubectl kgp

If you set up the override for YAML output, you should see pod information in YAML format.

Test 2: Create a Namespace

1
kubectl crns

This should create a namespace called “dev-project-01”.

Test 3: Delete with Confirmation

1
kubectl delete ns dev-project-01

If you set up the delete override, you should see a confirmation prompt asking if you’re sure you want to delete.

Troubleshooting

If your aliases aren’t working:

  1. Check that kuberc is enabled:

    1
    echo $KUBECTL_KUBERC

    Should output: true

  2. Check kubectl version:

    1
    kubectl version --client

    Should be 1.33 or higher

  3. Check if the kuberc file exists:

    1
    ls -la ~/.kube/kuberc

    Should show the file

  4. Check for YAML syntax errors:

    • Make sure indentation is correct (use spaces, not tabs)
    • Make sure there are no typos in apiVersion or kind

Step 9: Pro Tips and Best Practices

Combine with Shell Aliases

You can make things even shorter by adding a shell alias for kubectl itself:

1
echo 'alias k=kubectl' >> ~/.bashrc

Now instead of kubectl kgp, you can just type k kgp!

Use Tab Completion

Kubectl supports tab completion, and it works with kuberc aliases too! After typing a few letters, press Tab to autocomplete.

To enable completion (if not already enabled):

For Bash:

1
kubectl completion bash >> ~/.bashrc

For Zsh:

1
kubectl completion zsh >> ~/.zshrc

Version Control Your Kuberc

Since kuberc is just a file, you can:

  • Back it up to GitHub
  • Share it with your team
  • Keep different versions for different projects

Temporarily Disable Kuberc

If you need to temporarily turn off kuberc:

1
export KUBERC=off

Or if using the feature gate:

1
export KUBECTL_KUBERC=false

Common Aliases You Might Want

Here are some popular aliases used by Kubernetes professionals:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
aliases:
# Quick pod operations
- name: kgp
command: get pods

- name: kdp
command: describe pod

- name: kdelp
command: delete pod

# Deployments
- name: kgd
command: get deployments

- name: kdd
command: describe deployment

# Services
- name: kgs
command: get services

- name: kds
command: describe service

# Namespaces
- name: kgns
command: get namespaces

# Config and contexts
- name: kgc
command: config get-contexts

- name: kuc
command: config use-context

# Logs
- name: klf
command: logs
appendArgs:
- --follow

# Execute commands in pods
- name: kex
command: exec
appendArgs:
- --stdin
- --tty

Quick Reference

Enable kuberc:

1
export KUBECTL_KUBERC=true

Kuberc file location:

1
~/.kube/kuberc

Basic kuberc structure:

1
2
3
4
5
6
7
apiVersion: kubectl.config.k8s.io/v1beta1
kind: Preference
aliases:
- name: shortcut
command: kubectl-command
appendArgs:
- additional-args

Check if it’s working:

1
kubectl <your-alias>

Conclusion

Congratulations! You now know how to:

  • Set up kubectl aliases using the new kuberc feature
  • Create custom shortcuts for your most-used commands
  • Use overrides to set default behaviors
  • Troubleshoot common issues

Using kuberc will save you time and make working with Kubernetes much more enjoyable. Start with a few basic aliases and gradually add more as you discover which commands you use most often.

Happy Coding