gitmyhub

kubectl-aliases

Nu ★ 3.7k updated 1y ago

Programmatically generated handy kubectl aliases.

kubectl is the command-line tool used to manage Kubernetes clusters. Even simple operations require typing long commands with resource types, flags, and namespace names. This repository provides a pre-generated file of roughly 800 shell aliases that abbreviate common kubectl commands into short combinations of letters, so you type less and make fewer mistakes.

The alias names follow a consistent pattern. Starting with k for kubectl, you add letters for the command, the resource type, and any flags. For example, kgpo expands to kubectl get pod, and ksysgpo expands to kubectl --namespace=kube-system get pod. Resource abbreviations like po for pod, dep for deployment, svc for service, and sec for secret combine with command abbreviations like g for get, d for describe, rm for delete, and lo for logs. Once you internalize the pattern, the short names become predictable rather than arbitrary.

The aliases are not written by hand. A Python script generates all permutations of commands, resource types, and flags, producing the alias file automatically. The script accepts a shell argument and can output aliases for bash/zsh, fish, or Nushell.

Installation is a one-time step: download the alias file for your shell and add a line to your shell startup file to load it. The fish shell version uses abbreviations instead of aliases, which shows the full expanded command in the terminal before it executes, so you always see what will actually run.

Sourcing the file adds roughly 30 to 45 milliseconds to shell startup time, according to the README. Adding more resource types would increase that further, which is why the project asks users to fork rather than adding niche resources to the main list.