kubectl.plugin.zsh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. # List all contexts
  23. alias kcgc='kubectl config get-contexts'
  24. # General aliases
  25. alias kdel='kubectl delete'
  26. alias kdelf='kubectl delete -f'
  27. # Pod management.
  28. alias kgp='kubectl get pods'
  29. alias kgpw='kgp --watch'
  30. alias kgpwide='kgp -o wide'
  31. alias kep='kubectl edit pods'
  32. alias kdp='kubectl describe pods'
  33. alias kdelp='kubectl delete pods'
  34. # get pod by label: kgpl "app=myapp" -n myns
  35. alias kgpl='kgp -l'
  36. # Service management.
  37. alias kgs='kubectl get svc'
  38. alias kgsw='kgs --watch'
  39. alias kgswide='kgs -o wide'
  40. alias kes='kubectl edit svc'
  41. alias kds='kubectl describe svc'
  42. alias kdels='kubectl delete svc'
  43. # Ingress management
  44. alias kgi='kubectl get ingress'
  45. alias kei='kubectl edit ingress'
  46. alias kdi='kubectl describe ingress'
  47. alias kdeli='kubectl delete ingress'
  48. # Namespace management
  49. alias kgns='kubectl get namespaces'
  50. alias kens='kubectl edit namespace'
  51. alias kdns='kubectl describe namespace'
  52. alias kdelns='kubectl delete namespace'
  53. alias kcn='kubectl config set-context $(kubectl config current-context) --namespace'
  54. # ConfigMap management
  55. alias kgcm='kubectl get configmaps'
  56. alias kecm='kubectl edit configmap'
  57. alias kdcm='kubectl describe configmap'
  58. alias kdelcm='kubectl delete configmap'
  59. # Secret management
  60. alias kgsec='kubectl get secret'
  61. alias kdsec='kubectl describe secret'
  62. alias kdelsec='kubectl delete secret'
  63. # Deployment management.
  64. alias kgd='kubectl get deployment'
  65. alias kgdw='kgd --watch'
  66. alias kgdwide='kgd -o wide'
  67. alias ked='kubectl edit deployment'
  68. alias kdd='kubectl describe deployment'
  69. alias kdeld='kubectl delete deployment'
  70. alias ksd='kubectl scale deployment'
  71. alias krsd='kubectl rollout status deployment'
  72. kres(){
  73. kubectl set env $@ REFRESHED_AT=$(date +%Y%m%d%H%M%S)
  74. }
  75. # Rollout management.
  76. alias kgrs='kubectl get rs'
  77. alias krh='kubectl rollout history'
  78. alias kru='kubectl rollout undo'
  79. # Statefulset management.
  80. alias kgss='kubectl get statefulset'
  81. alias kgssw='kgss --watch'
  82. alias kgsswide='kgss -o wide'
  83. alias kess='kubectl edit statefulset'
  84. alias kdss='kubectl describe statefulset'
  85. alias kdelss='kubectl delete statefulset'
  86. alias ksss='kubectl scale statefulset'
  87. alias krsss='kubectl rollout status statefulset'
  88. # Port forwarding
  89. alias kpf="kubectl port-forward"
  90. # Tools for accessing all information
  91. alias kga='kubectl get all'
  92. alias kgaa='kubectl get all --all-namespaces'
  93. # Logs
  94. alias kl='kubectl logs'
  95. alias klf='kubectl logs -f'
  96. # File copy
  97. alias kcp='kubectl cp'
  98. # Node Management
  99. alias kgno='kubectl get nodes'
  100. alias keno='kubectl edit node'
  101. alias kdno='kubectl describe node'
  102. alias kdelno='kubectl delete node'
  103. # PVC management.
  104. alias kgpvc='kubectl get pvc'
  105. alias kgpvcw='kgpvc --watch'
  106. alias kepvc='kubectl edit pvc'
  107. alias kdpvc='kubectl describe pvc'
  108. alias kdelpvc='kubectl delete pvc'