Sign In

Curriculum 5: Kubectl CLI Cheat Sheet

Shortcuts & Aliases

10 min · 15 XP

Shortcuts and Aliases

kubectl commands can get long. Using short resource names and shell aliases will save you hundreds of keystrokes every day.

Built-in Short Names

Kubernetes provides official short names for most resource types. You can use these anywhere you would use the full name:

# Instead of full names...
kubectl get pods
kubectl get services
kubectl get deployments
kubectl get namespaces
kubectl get nodes
kubectl get configmaps
kubectl get persistentvolumeclaims

# ...use short names
kubectl get po
kubectl get svc
kubectl get deploy
kubectl get ns
kubectl get no
kubectl get cm
kubectl get pvc

To see all available short names, run:

kubectl api-resources

The SHORTNAMES column shows the abbreviation for each resource type.

Common Short Name Reference

Full NameShort Name
podspo
servicessvc
deploymentsdeploy
namespacesns
nodesno
configmapscm
secrets(none)
persistentvolumeclaimspvc
persistentvolumespv
serviceaccountssa
replicasetsrs
daemonsetsds
statefulsetssts
ingressesing
endpointsep

Aliasing kubectl to k

The most popular alias in the Kubernetes world is shortening kubectl itself to k:

# Add to your .bashrc or .zshrc
alias k=kubectl

# Now use it
k get po
k describe svc my-service
k logs my-pod -f

Do not forget to set up completion for the alias too:

# Bash
complete -o default -F __start_kubectl k

# Zsh (add after sourcing kubectl completion)
compdef k=kubectl

More Useful Aliases

Power users often add additional aliases:

alias kgp='kubectl get pods'
alias kgs='kubectl get svc'
alias kgd='kubectl get deploy'
alias kaf='kubectl apply -f'
alias kdel='kubectl delete'
alias klog='kubectl logs -f'
alias kex='kubectl exec -it'

Key Takeaways

  • Short names like po, svc, and deploy are built into kubectl
  • Aliasing kubectl to k is the single biggest time saver
  • Set up shell completion for your aliases so Tab completion still works
  • Create additional aliases for commands you run frequently
  • Run kubectl api-resources to discover all available short names