Blame
3e0f3b | Tebby Dog | 2025-07-06 21:08:52 | 1 | # Fish-Aliases |
2 | ||||
3 | This is a list of aliases I use to reduce typing when managing my Kubernetes cluster, these are for the fish console |
|||
4 | ||||
5 | ```bash |
|||
6 | ||||
7 | # --- Color Definitions --- |
|||
8 | set -x BLU '\033[0;34m' |
|||
9 | set -x RED '\033[0;31m' |
|||
10 | set -x GRN '\033[0;32m' |
|||
11 | set -x NC '\033[0m' |
|||
12 | ||||
13 | # --- Kubectl Aliases --- |
|||
14 | alias k='kubectl' |
|||
15 | ||||
16 | # Resource Management Aliases |
|||
17 | alias kgp='kubectl get pods' |
|||
18 | alias kgpw='kubectl get pods -o wide --sort-by=".spec.nodeName"' |
|||
19 | alias kga='kubectl get all' |
|||
20 | alias kgn='kubectl get namespaces' |
|||
21 | alias kgi='kubectl get ingress' |
|||
22 | alias kgc='kubectl get configmaps' |
|||
23 | alias kgs='kubectl get services' |
|||
24 | alias kgss='kubectl get statefulsets' |
|||
25 | ||||
26 | # Create Aliases |
|||
27 | alias kcc='kubectl create configmap' |
|||
28 | alias kcn='kubectl create namespace' |
|||
29 | alias kcd='kubectl create deployment' |
|||
30 | ||||
31 | # Delete/Remove Aliases |
|||
32 | alias krp='kubectl delete' |
|||
33 | alias krc='kubectl delete configmap' |
|||
34 | alias kri='kubectl delete ingress' |
|||
35 | alias krn='kubectl delete namespace' |
|||
36 | alias krd='kubectl delete deployment' |
|||
37 | alias krs='kubectl delete service' |
|||
38 | alias krap='kubectl delete all --all -n' |
|||
39 | ||||
40 | # Edit and Apply Aliases |
|||
41 | alias kec='kubectl edit configmap' |
|||
42 | alias kaf='kubectl apply -f' |
|||
43 | alias krf='kubectl delete -f' |
|||
44 | alias ked='kubectl edit deployment' |
|||
45 | ||||
46 | # Logging and Monitoring |
|||
47 | alias kgl='kubectl logs -f' |
|||
48 | alias kwp='kubectl logs -f' |
|||
49 | alias wkga='watch kubectl get all' |
|||
50 | alias wkgp='watch kubectl get pods' |
|||
51 | alias ktn='kubectl top nodes' |
|||
52 | alias ktp='kubectl top pods' |
|||
53 | alias ktpm='kubectl top pods --sort-by=memory' |
|||
54 | alias ktpc='kubectl top pods --sort-by=cpu' |
|||
55 | ||||
56 | # Namespace and Context Management |
|||
57 | alias ksn='kubectl config set-context --current --namespace' |
|||
58 | alias ksxh='set KUBECONFIG ~/.kube/config-hogwarts' |
|||
59 | alias ksxg='set KUBECONFIG ~/.kube/config-gondor' |
|||
60 | alias ksx='kubectl config use-context' |
|||
61 | alias kgx='kubectl config get-contexts' |
|||
62 | alias kcx='kubectl config use-context' |
|||
63 | ||||
64 | # Scaling and Pause |
|||
65 | alias kp='kubectl scale deployment --replicas=0' |
|||
66 | alias kr='kubectl scale deployment --replicas=1' |
|||
67 | alias kts='talosctl shutdown -n' |
|||
68 | alias ktr='talosctl reboot -n' |
|||
69 | ||||
70 | # Advanced Helpers |
|||
71 | alias kdp='kubectl describe pods' |
|||
72 | alias tdash='talosctl --nodes 0.0.0.0 --endpoints 0.0.0.1 dashboard' # Replace 0.0.0.0 with your controlplane node ip, replace 0.0.0.1 with your endpoint for the dashboard can be the same as the controlplane |
|||
73 | alias kdd='kubectl describe deployments' |
|||
74 | alias kdn='kubectl describe nodes' |
|||
75 | alias random='openssl rand -hex' |
|||
76 | ||||
77 | function kgd # this will only work with pbcopy installed |
|||
78 | # Get current namespace |
|||
79 | set namespace (kubectl config view --minify --output 'jsonpath={..namespace}') |
|||
80 | ||||
81 | # Get all services in the current namespace |
|||
82 | set services (kubectl get services -o name | sed 's/service\///') |
|||
83 | ||||
84 | # Check if any services exist |
|||
85 | if test (count $services) -eq 0 |
|||
86 | echo "No services found in namespace: $namespace" |
|||
87 | return 1 |
|||
88 | end |
|||
89 | ||||
90 | # If there's only one service, automatically select it |
|||
91 | if test (count $services) -eq 1 |
|||
92 | set selected_service $services[1] |
|||
93 | set selection 1 |
|||
94 | else |
|||
95 | # Display services with numbers |
|||
96 | echo "Select a service from namespace '$namespace':" |
|||
97 | for i in (seq (count $services)) |
|||
98 | echo "$i. $services[$i]" |
|||
99 | end |
|||
100 | ||||
101 | # Get user selection |
|||
102 | read -P "Enter selection number: " selection |
|||
103 | end |
|||
104 | ||||
105 | # Validate selection |
|||
106 | if test "$selection" -ge 1 -a "$selection" -le (count $services) |
|||
107 | set selected_service $services[$selection] |
|||
108 | ||||
109 | # Get the port for the selected service |
|||
110 | set port_data (kubectl get service $selected_service -o jsonpath='{.spec.ports[0].port}') |
|||
111 | ||||
112 | # Create the URL with port |
|||
113 | set url "$selected_service.$namespace.svc.cluster.local:$port_data" |
|||
114 | ||||
115 | # Output the result |
|||
116 | echo $url |
|||
117 | ||||
118 | # Copy to clipboard if pbcopy/xclip is available |
|||
119 | if type -q pbcopy |
|||
120 | echo $url | pbcopy |
|||
121 | echo "URL copied to clipboard!" |
|||
122 | else if type -q xclip |
|||
123 | echo $url | xclip -selection clipboard |
|||
124 | echo "URL copied to clipboard!" |
|||
125 | end |
|||
126 | else |
|||
127 | echo "Invalid selection!" |
|||
128 | return 1 |
|||
129 | end |
|||
130 | end |
|||
131 | ||||
132 | function tkgd |
|||
133 | # Get current namespace |
|||
134 | set namespace (tsh kubectl config view --minify --output 'jsonpath={..namespace}') |
|||
135 | ||||
136 | # Get all services in the current namespace |
|||
137 | set services (tsh kubectl get services -o name | sed 's/service\///') |
|||
138 | ||||
139 | # Check if any services exist |
|||
140 | if test (count $services) -eq 0 |
|||
141 | echo "No services found in namespace: $namespace" |
|||
142 | return 1 |
|||
143 | end |
|||
144 | ||||
145 | # Display services with numbers |
|||
146 | echo "Select a service from namespace '$namespace':" |
|||
147 | for i in (seq (count $services)) |
|||
148 | echo "$i. $services[$i]" |
|||
149 | end |
|||
150 | ||||
151 | # Get user selection |
|||
152 | read -P "Enter selection number: " selection |
|||
153 | ||||
154 | # Validate selection |
|||
155 | if test "$selection" -ge 1 -a "$selection" -le (count $services) |
|||
156 | set selected_service $services[$selection] |
|||
157 | ||||
158 | # Create the URL |
|||
159 | set url "$selected_service.$namespace.svc.cluster.local" |
|||
160 | ||||
161 | # Output the result |
|||
162 | echo $url |
|||
163 | ||||
164 | # Copy to clipboard if pbcopy/xclip is available |
|||
165 | if type -q pbcopy |
|||
166 | echo $url | pbcopy |
|||
167 | echo "URL copied to clipboard!" |
|||
168 | else if type -q xclip |
|||
169 | echo $url | xclip -selection clipboard |
|||
170 | echo "URL copied to clipboard!" |
|||
171 | end |
|||
172 | else |
|||
173 | echo "Invalid selection!" |
|||
174 | return 1 |
|||
175 | end |
|||
176 | end |
|||
177 | ||||
178 | ## These are duplicates of the above but using teleport to connect to the cluster |
|||
179 | ||||
180 | # --- Kubectl Aliases --- |
|||
181 | alias tk='tsh kubectl' |
|||
182 | ||||
183 | # Resource Management Aliases |
|||
184 | alias tkgp='tsh kubectl get pods' |
|||
185 | alias tkgpw='tsh kubectl get pods -o wide --sort-by=".spec.nodeName"' |
|||
186 | alias tkga='tsh kubectl get all' |
|||
187 | alias tkgn='tsh kubectl get namespaces' |
|||
188 | alias tkgi='tsh kubectl get ingress' |
|||
189 | alias tkgc='tsh kubectl get configmaps' |
|||
190 | alias tkgs='tsh kubectl get services' |
|||
191 | alias tkgss='tsh kubectl get statefulsets' |
|||
192 | ||||
193 | # Create Aliases |
|||
194 | alias tkcc='tsh kubectl create configmap' |
|||
195 | alias tkcn='tsh kubectl create namespace' |
|||
196 | alias tkcd='tsh kubectl create deployment' |
|||
197 | ||||
198 | # Delete/Remove Aliases |
|||
199 | alias tkrp='tsh kubectl delete' |
|||
200 | alias tkrc='tsh kubectl delete configmap' |
|||
201 | alias tkri='tsh kubectl delete ingress' |
|||
202 | alias tkrn='tsh kubectl delete namespace' |
|||
203 | alias tkrd='tsh kubectl delete deployment' |
|||
204 | alias tkrs='tsh kubectl delete service' |
|||
205 | alias tkrap='tsh kubectl delete all --all -n' |
|||
206 | ||||
207 | # Edit and Apply Aliases |
|||
208 | alias tkec='tsh kubectl edit configmap' |
|||
209 | alias tkaf='tsh kubectl apply -f' |
|||
210 | alias tkrf='tsh kubectl delete -f' |
|||
211 | alias tked='tsh kubectl edit deployment' |
|||
212 | ||||
213 | # Logging and Monitoring |
|||
214 | alias tkgl='tsh kubectl logs -f' |
|||
215 | alias tkwp='tsh kubectl logs -f' |
|||
216 | alias twkga='watch tsh kubectl get all' |
|||
217 | alias twkgp='watch tsh kubectl get pods' |
|||
218 | alias tktn='tsh kubectl top nodes' |
|||
219 | alias tktp='tsh kubectl top pods' |
|||
220 | alias tktpm='tsh kubectl top pods --sort-by=memory' |
|||
221 | alias tktpc='tsh kubectl top pods --sort-by=cpu' |
|||
222 | ||||
223 | # Namespace and Context Management |
|||
224 | alias tksn='tsh kubectl config set-context --current --namespace' |
|||
225 | alias tksxh='tsh kube login hogwarts' |
|||
226 | alias tksxg='tsh kube login gondor' |
|||
227 | alias tksx='tsh kubectl config use-context' |
|||
228 | alias tkgx='tsh kubectl config get-contexts' |
|||
229 | alias tkcx='tsh kubectl config use-context' |
|||
230 | ||||
231 | # Scaling and Pause |
|||
232 | alias tkp='tsh kubectl scale deployment --replicas=0' |
|||
233 | alias tkr='tsh kubectl scale deployment --replicas=1' |
|||
234 | alias tkts='talosctl shutdown -n' |
|||
235 | alias tktr='talosctl reboot -n' |
|||
236 | alias ts='talosctl shutdown -n 0.0.0.0,0.0.0.1' # Replace 0.0.0.0 with a comma separated list of IPs of the Talos nodes |
|||
237 | ||||
238 | # Advanced Helpers |
|||
239 | alias tkdp='tsh kubectl describe pods' |
|||
240 | alias tdash='talosctl --nodes 0.0.0.0 --endpoints 0.0.0.1 dashboard' # Replace 0.0.0.0 with your controlplane node ip, replace 0.0.0.1 with your endpoint for the dashboard can be the same as the controlplane |
|||
241 | alias tkdd='tsh kubectl describe deployments' |
|||
242 | alias tkdn='tsh kubectl describe nodes' |
|||
243 | ||||
244 | # --- Kubernetes Helper Aliases (Fish Function) --- |
|||
245 | ||||
246 | function kh |
|||
247 | clear |
|||
248 | # Guidance for Customization |
|||
249 | printf "\033[0;31mYou can modify these aliases in ~/.config/fish/config.fish\033[0m\n\n" |
|||
250 | ||||
251 | # Basic Aliases |
|||
252 | printf "\033[0;32mBasic Aliases\033[0m\n" |
|||
253 | printf "\033[0;34mk\033[0m - Short for 'kubectl'\n" |
|||
254 | printf "\033[0;34mkh\033[0m - Display this help and list all aliases\n\n" |
|||
255 | ||||
256 | # Resource Management |
|||
257 | printf "\033[0;32mResource Management\033[0m\n" |
|||
258 | printf "\033[0;34mkgp\033[0m - Get pods in current namespace\n" |
|||
259 | printf "\033[0;34mkgpw\033[0m - Get pods with wide details, sorted by node\n" |
|||
260 | printf "\033[0;34mkga\033[0m - Get all resources in current namespace\n" |
|||
261 | printf "\033[0;34mkgn\033[0m - Get namespaces\n" |
|||
262 | printf "\033[0;34mkgi\033[0m - Get ingress in current namespace\n" |
|||
263 | printf "\033[0;34mkgc\033[0m - Get configmaps in current namespace\n" |
|||
264 | printf "\033[0;34mkgd\033[0m - Get deployments\n" |
|||
265 | printf "\033[0;34mkgss\033[0m - Get statefulsets\n\n" |
|||
266 | ||||
267 | # Creating Resources |
|||
268 | printf "\033[0;32mCreating Resources\033[0m\n" |
|||
269 | printf "\033[0;34mkcc\033[0m - Create a configmap\n" |
|||
270 | printf "\033[0;34mkcn\033[0m - Create a namespace\n" |
|||
271 | printf "\033[0;34mkcd\033[0m - Create a deployment\n\n" |
|||
272 | ||||
273 | # Deleting/Removing |
|||
274 | printf "\033[0;32mDeleting/Removing\033[0m\n" |
|||
275 | printf "\033[0;34mkrp\033[0m - Remove a pod\n" |
|||
276 | printf "\033[0;34mkrc\033[0m - Remove a configmap\n" |
|||
277 | printf "\033[0;34mkrd\033[0m - Remove a deployment\n" |
|||
278 | printf "\033[0;34mkrs\033[0m - Remove a service\n" |
|||
279 | printf "\033[0;34mkrn\033[0m - Remove a namespace\n" |
|||
280 | printf "\033[0;34mkrp\033[0m - Remove a pod\n\n" |
|||
281 | ||||
282 | # Editing and Applying |
|||
283 | printf "\033[0;32mEditing and Applying\033[0m\n" |
|||
284 | printf "\033[0;34mkec\033[0m - Edit a configmap\n" |
|||
285 | printf "\033[0;34mraft\033[0m - Apply file to current namespace\n" |
|||
286 | printf "\033[0;34mkaf\033[0m - Edit a deployment\n\n" |
|||
287 | ||||
288 | # Logging and Monitoring |
|||
289 | printf "\033[0;32mLogging and Monitoring\033[0m\n" |
|||
290 | printf "\033[0;34mkgl\033[0m - Get logs\n" |
|||
291 | printf "\033[0;34mkwp\033[0m - Watch logs of a pod\n" |
|||
292 | printf "\033[0;34mktn\033[0m - Get node usage stats\n" |
|||
293 | printf "\033[0;34mktp\033[0m - Get pod usage stats\n" |
|||
294 | printf "\033[0;34mktpc\033[0m - Pod stats sorted by CPU\n\n" |
|||
295 | ||||
296 | # Namespace and Context |
|||
297 | printf "\033[0;32mNamespace and Context\033[0m\n" |
|||
298 | printf "\033[0;34mksn\033[0m - Set current namespace\n" |
|||
299 | printf "\033[0;34mksx\033[0m - Set current context\n" |
|||
300 | printf "\033[0;34mksxh\033[0m - Switch context to Hogwarts\n" |
|||
301 | printf "\033[0;34mksxg\033[0m - Switch context to Gondor\n" |
|||
302 | printf "\033[0;34mkgx\033[0m - Get contexts (namespaces)\n\n" |
|||
303 | ||||
304 | # Scaling and Pause |
|||
305 | printf "\033[0;32mScaling and Pause\033[0m\n" |
|||
306 | printf "\033[0;34mkp\033[0m - Pause a pod/deployment (scale to 0)\n" |
|||
307 | printf "\033[0;34mkr\033[0m - Resume a deployment (scale to 1)\n\n" |
|||
308 | ||||
309 | # Advanced Helpers |
|||
310 | printf "\033[0;32mAdvanced Helpers\033[0m\n" |
|||
311 | printf "\033[0;34mkdp\033[0m - Describe pods\n" |
|||
312 | printf "\033[0;34mkdd\033[0m - Describe deployments\n" |
|||
313 | printf "\033[0;34mkdn\033[0m - Describe nodes\n\n" |
|||
314 | ||||
315 | # Additional Commands |
|||
316 | printf "\033[0;31mAdditional Commands\033[0m\n" |
|||
317 | printf "\033[0;34mrandom\033[0m - Create a random string\n" |
|||
318 | printf "\033[0;34mdash\033[0m - Show Talos Dashboard\n" |
|||
319 | printf "kubectl create secret generic my-secret --from-literal=username=admin\n" |
|||
320 | printf "random 32\n" |
|||
321 | printf "helm show values openebs/openebs > values-openebs.yaml\n" |
|||
322 | printf "Add 't' to the beginning of any alias to use teleport\n" |
|||
323 | printf "\033[0;34tr\033[0m - Reboot all Nodes" |
|||
324 | printf "\033[0;34ts\033[0m - Shutdown all Nodes" |
|||
325 | end |
|||
326 | ||||
327 | ``` |