kubectl.plugin.zsh 4.2 KB

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