kubectl.plugin.zsh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. if (( $+commands[kubectl] )); then
  2. __KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"
  3. if [[ ! -f $__KUBECTL_COMPLETION_FILE ]]; then
  4. kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
  5. fi
  6. [[ -f $__KUBECTL_COMPLETION_FILE ]] && source $__KUBECTL_COMPLETION_FILE
  7. unset __KUBECTL_COMPLETION_FILE
  8. fi
  9. # This command is used a LOT both below and in daily life
  10. alias k=kubectl
  11. # Execute a kubectl command against all namespaces
  12. alias kca='f(){ kubectl "$@" --all-namespaces; unset -f f; }; f'
  13. # Apply a YML file
  14. alias kaf='kubectl apply -f'
  15. # Drop into an interactive terminal on a container
  16. alias keti='kubectl exec -ti'
  17. # Manage configuration quickly to switch contexts between local, dev ad staging.
  18. alias kcuc='kubectl config use-context'
  19. alias kcsc='kubectl config set-context'
  20. alias kcdc='kubectl config delete-context'
  21. alias kccc='kubectl config current-context'
  22. # General aliases
  23. alias kdel='kubectl delete'
  24. alias kdelf='kubectl delete -f'
  25. # Pod management.
  26. alias kgp='kubectl get pods'
  27. alias kgpw='kgp --watch'
  28. alias kgpwide='kgp -o wide'
  29. alias kep='kubectl edit pods'
  30. alias kdp='kubectl describe pods'
  31. alias kdelp='kubectl delete pods'
  32. # get pod by label: kgpl "app=myapp" -n myns
  33. alias kgpl='kgp -l'
  34. # Service management.
  35. alias kgs='kubectl get svc'
  36. alias kgsw='kgs --watch'
  37. alias kgswide='kgs -o wide'
  38. alias kes='kubectl edit svc'
  39. alias kds='kubectl describe svc'
  40. alias kdels='kubectl delete svc'
  41. # Ingress management
  42. alias kgi='kubectl get ingress'
  43. alias kei='kubectl edit ingress'
  44. alias kdi='kubectl describe ingress'
  45. alias kdeli='kubectl delete ingress'
  46. # Namespace management
  47. alias kgns='kubectl get namespaces'
  48. alias kens='kubectl edit namespace'
  49. alias kdns='kubectl describe namespace'
  50. alias kdelns='kubectl delete namespace'
  51. alias kcn='kubectl config set-context $(kubectl config current-context) --namespace'
  52. # ConfigMap management
  53. alias kgcm='kubectl get configmaps'
  54. alias kecm='kubectl edit configmap'
  55. alias kdcm='kubectl describe configmap'
  56. alias kdelcm='kubectl delete configmap'
  57. # Secret management
  58. alias kgsec='kubectl get secret'
  59. alias kdsec='kubectl describe secret'
  60. alias kdelsec='kubectl delete secret'
  61. # Deployment management.
  62. alias kgd='kubectl get deployment'
  63. alias kgdw='kgd --watch'
  64. alias kgdwide='kgd -o wide'
  65. alias ked='kubectl edit deployment'
  66. alias kdd='kubectl describe deployment'
  67. alias kdeld='kubectl delete deployment'
  68. alias ksd='kubectl scale deployment'
  69. alias krsd='kubectl rollout status deployment'
  70. kres(){
  71. kubectl set env $@ REFRESHED_AT=$(date +%Y%m%d%H%M%S)
  72. }
  73. # Rollout management.
  74. alias kgrs='kubectl get rs'
  75. alias krh='kubectl rollout history'
  76. alias kru='kubectl rollout undo'
  77. # Port forwarding
  78. alias kpf="kubectl port-forward"
  79. # Tools for accessing all information
  80. alias kga='kubectl get all'
  81. alias kgaa='kubectl get all --all-namespaces'
  82. # Logs
  83. alias kl='kubectl logs'
  84. alias klf='kubectl logs -f'
  85. # File copy
  86. alias kcp='kubectl cp'
  87. # Node Management
  88. alias kgno='kubectl get nodes'
  89. alias keno='kubectl edit node'
  90. alias kdno='kubectl describe node'
  91. alias kdelno='kubectl delete node'