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 Name | Short Name |
|---|---|
| pods | po |
| services | svc |
| deployments | deploy |
| namespaces | ns |
| nodes | no |
| configmaps | cm |
| secrets | (none) |
| persistentvolumeclaims | pvc |
| persistentvolumes | pv |
| serviceaccounts | sa |
| replicasets | rs |
| daemonsets | ds |
| statefulsets | sts |
| ingresses | ing |
| endpoints | ep |
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, anddeployare built into kubectl - Aliasing
kubectltokis 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-resourcesto discover all available short names