1 if (( $+commands[kubectl] )); then
2 # If the completion file does not exist, generate it and then source it
3 # Otherwise, source it and regenerate in the background
4 if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
5 kubectl completion zsh | tee "$ZSH_CACHE_DIR/completions/_kubectl" >/dev/null
6 source "$ZSH_CACHE_DIR/completions/_kubectl"
8 source "$ZSH_CACHE_DIR/completions/_kubectl"
9 kubectl completion zsh | tee "$ZSH_CACHE_DIR/completions/_kubectl" >/dev/null &|
13 # This command is used a LOT both below and in daily life
16 # Execute a kubectl command against all namespaces
17 alias kca='_kca(){ kubectl "$@" --all-namespaces; unset -f _kca; }; _kca'
20 alias kaf='kubectl apply -f'
22 # Drop into an interactive terminal on a container
23 alias keti='kubectl exec -t -i'
25 # Manage configuration quickly to switch contexts between local, dev ad staging.
26 alias kcuc='kubectl config use-context'
27 alias kcsc='kubectl config set-context'
28 alias kcdc='kubectl config delete-context'
29 alias kccc='kubectl config current-context'
32 alias kcgc='kubectl config get-contexts'
35 alias kdel='kubectl delete'
36 alias kdelf='kubectl delete -f'
39 alias kgp='kubectl get pods'
40 alias kgpa='kubectl get pods --all-namespaces'
41 alias kgpw='kgp --watch'
42 alias kgpwide='kgp -o wide'
43 alias kep='kubectl edit pods'
44 alias kdp='kubectl describe pods'
45 alias kdelp='kubectl delete pods'
46 alias kgpall='kubectl get pods --all-namespaces -o wide'
48 # get pod by label: kgpl "app=myapp" -n myns
51 # get pod by namespace: kgpn kube-system"
55 alias kgs='kubectl get svc'
56 alias kgsa='kubectl get svc --all-namespaces'
57 alias kgsw='kgs --watch'
58 alias kgswide='kgs -o wide'
59 alias kes='kubectl edit svc'
60 alias kds='kubectl describe svc'
61 alias kdels='kubectl delete svc'
64 alias kgi='kubectl get ingress'
65 alias kgia='kubectl get ingress --all-namespaces'
66 alias kei='kubectl edit ingress'
67 alias kdi='kubectl describe ingress'
68 alias kdeli='kubectl delete ingress'
70 # Namespace management
71 alias kgns='kubectl get namespaces'
72 alias kens='kubectl edit namespace'
73 alias kdns='kubectl describe namespace'
74 alias kdelns='kubectl delete namespace'
75 alias kcn='kubectl config set-context --current --namespace'
77 # ConfigMap management
78 alias kgcm='kubectl get configmaps'
79 alias kgcma='kubectl get configmaps --all-namespaces'
80 alias kecm='kubectl edit configmap'
81 alias kdcm='kubectl describe configmap'
82 alias kdelcm='kubectl delete configmap'
85 alias kgsec='kubectl get secret'
86 alias kgseca='kubectl get secret --all-namespaces'
87 alias kdsec='kubectl describe secret'
88 alias kdelsec='kubectl delete secret'
90 # Deployment management.
91 alias kgd='kubectl get deployment'
92 alias kgda='kubectl get deployment --all-namespaces'
93 alias kgdw='kgd --watch'
94 alias kgdwide='kgd -o wide'
95 alias ked='kubectl edit deployment'
96 alias kdd='kubectl describe deployment'
97 alias kdeld='kubectl delete deployment'
98 alias ksd='kubectl scale deployment'
99 alias krsd='kubectl rollout status deployment'
102 kubectl set env $@ REFRESHED_AT=$(date +%Y%m%d%H%M%S)
105 # Rollout management.
106 alias kgrs='kubectl get replicaset'
107 alias kdrs='kubectl describe replicaset'
108 alias kers='kubectl edit replicaset'
109 alias krh='kubectl rollout history'
110 alias kru='kubectl rollout undo'
112 # Statefulset management.
113 alias kgss='kubectl get statefulset'
114 alias kgssa='kubectl get statefulset --all-namespaces'
115 alias kgssw='kgss --watch'
116 alias kgsswide='kgss -o wide'
117 alias kess='kubectl edit statefulset'
118 alias kdss='kubectl describe statefulset'
119 alias kdelss='kubectl delete statefulset'
120 alias ksss='kubectl scale statefulset'
121 alias krsss='kubectl rollout status statefulset'
124 alias kpf="kubectl port-forward"
126 # Tools for accessing all information
127 alias kga='kubectl get all'
128 alias kgaa='kubectl get all --all-namespaces'
131 alias kl='kubectl logs'
132 alias kl1h='kubectl logs --since 1h'
133 alias kl1m='kubectl logs --since 1m'
134 alias kl1s='kubectl logs --since 1s'
135 alias klf='kubectl logs -f'
136 alias klf1h='kubectl logs --since 1h -f'
137 alias klf1m='kubectl logs --since 1m -f'
138 alias klf1s='kubectl logs --since 1s -f'
141 alias kcp='kubectl cp'
144 alias kgno='kubectl get nodes'
145 alias keno='kubectl edit node'
146 alias kdno='kubectl describe node'
147 alias kdelno='kubectl delete node'
150 alias kgpvc='kubectl get pvc'
151 alias kgpvca='kubectl get pvc --all-namespaces'
152 alias kgpvcw='kgpvc --watch'
153 alias kepvc='kubectl edit pvc'
154 alias kdpvc='kubectl describe pvc'
155 alias kdelpvc='kubectl delete pvc'
157 # Service account management.
158 alias kdsa="kubectl describe sa"
159 alias kdelsa="kubectl delete sa"
161 # DaemonSet management.
162 alias kgds='kubectl get daemonset'
163 alias kgdsw='kgds --watch'
164 alias keds='kubectl edit daemonset'
165 alias kdds='kubectl describe daemonset'
166 alias kdelds='kubectl delete daemonset'
168 # CronJob management.
169 alias kgcj='kubectl get cronjob'
170 alias kecj='kubectl edit cronjob'
171 alias kdcj='kubectl describe cronjob'
172 alias kdelcj='kubectl delete cronjob'
175 alias kgj='kubectl get job'
176 alias kej='kubectl edit job'
177 alias kdj='kubectl describe job'
178 alias kdelj='kubectl delete job'
180 # Only run if the user actually has kubectl installed
181 if (( ${+_comps[kubectl]} )); then
182 function kj() { kubectl "$@" -o json | jq; }
183 function kjx() { kubectl "$@" -o json | fx; }
184 function ky() { kubectl "$@" -o yaml | yh; }