Cloud Native Tips & Tricks

kuberc is Here! Customizing kubectl with Kubernetes 1.33

Learn about kuberc, the new alpha feature in Kubernetes 1.33 that lets you customize kubectl! Discover how to use ~/.kube/kuberc to create aliases, set default flags, and streamline your Kubernetes workflow.

For years, Kubernetes users have wished for a dedicated way to personalize their kubectl command-line experience, much like .bashrc for shells or .gitconfig for Git. That wish is now taking its first official steps: kuberc has arrived as an alpha feature in Kubernetes 1.33.

This is a significant development for anyone who spends their day interacting with Kubernetes clusters, promising a more streamlined and efficient workflow, a native way of creating aliases and shortcuts.

What is kuberc?

kuberc is a configuration file that kubectl can now read on startup to apply user-defined preferences. The primary goal is to separate your personal kubectl settings—like aliases and default flags—from your kubeconfig file, which is primarily for cluster connection details and authentication.

With Kubernetes 1.33 (codenamed “Octarine”), kubectl can be configured to look for a ~/.kube/kuberc file (or a custom path) to load these personalizations.

The introduction of kuberc brings several powerful advantages:

Getting Started with kuberc (Alpha in v1.33)

Since kuberc is an alpha feature in Kubernetes 1.33, you need to opt-in to use it:

  1. Enable kuberc: Set the environment variable KUBECTL_KUBERC=true.

    export KUBECTL_KUBERC=true
    

    You might want to add this to your shell’s profile file (e.g., ~/.bashrc, ~/.zshrc) to enable it automatically in new terminal sessions.

  2. Create Your kuberc File: By default, kubectl will look for this file at ~/.kube/kuberc. You can also specify a different path using the --kuberc <path-to-your-kuberc-file> flag with your kubectl commands.

kuberc File Structure and Syntax:

The kuberc file uses a YAML format. Here’s a basic structure based on KEP-3104:

# ~/.kube/kuberc
apiVersion: kubectl.config.k8s.io/v1alpha1
kind: Preference
aliases:
    - name: klogs
      command: logs
      appendArgs:
          - --follow
          - --tail=50
    - name: kgp
      command: get
      appendArgs:
          - pods

overrides:
    - command: apply
      flags:
          - name: server-side
            default: "true"
    - command: delete
      flags:
          - name: interactive
            default: "true"

Example Usage with the above kuberc:

Command aliases

kubectl klogs my-pod-name

would expand to kubectl logs –follow –tail=50 my-pod-name

kubectl kgp -n my-namespace

would expand to kubectl get pods -n my-namespace

Override default flags

kubectl apply -f my-manifest.yaml

would automatically behave like kubectl apply –server-side=true -f my-manifest.yaml

kubectl delete pod my-pod

would prompt for confirmation as if kubectl delete –interactive=true pod my-pod was run.

Important Note for Alpha: As an alpha feature, the exact syntax and capabilities might evolve. Also, be aware that kubectl auto-completion for aliases defined in kuberc might not be fully supported yet.

Summary

The arrival of kuberc in Kubernetes 1.33 (alpha) is a game-changer for personalizing your kubectl workflow. It provides a clean, official way to manage aliases and default command behaviors, separate from your cluster configurations.

You can visit the KEP-3104 to learn more about the feature and its development. If you’ve updated your kubectl to 1.33 or newer, enable the KUBECTL_KUBERC environment variable and start experimenting with your own ~/.kube/kuberc file today.

Sign up for Cloud Native Newsletter

Curated monthly updates featuring the biggest news in the cloud native community, along with tutorials and blogs, delivered to your inbox.