Commit 3e0f3b

2025-07-06 21:08:52 Tebby Dog: Moved from 1-Guides
/dev/null .. 2-code/fish-aliases.md
@@ 0,0 1,327 @@
+# Fish-Aliases
+
+This is a list of aliases I use to reduce typing when managing my Kubernetes cluster, these are for the fish console
+
+```bash
+
+# --- Color Definitions ---
+set -x BLU '\033[0;34m'
+set -x RED '\033[0;31m'
+set -x GRN '\033[0;32m'
+set -x NC '\033[0m'
+
+# --- Kubectl Aliases ---
+alias k='kubectl'
+
+# Resource Management Aliases
+alias kgp='kubectl get pods'
+alias kgpw='kubectl get pods -o wide --sort-by=".spec.nodeName"'
+alias kga='kubectl get all'
+alias kgn='kubectl get namespaces'
+alias kgi='kubectl get ingress'
+alias kgc='kubectl get configmaps'
+alias kgs='kubectl get services'
+alias kgss='kubectl get statefulsets'
+
+# Create Aliases
+alias kcc='kubectl create configmap'
+alias kcn='kubectl create namespace'
+alias kcd='kubectl create deployment'
+
+# Delete/Remove Aliases
+alias krp='kubectl delete'
+alias krc='kubectl delete configmap'
+alias kri='kubectl delete ingress'
+alias krn='kubectl delete namespace'
+alias krd='kubectl delete deployment'
+alias krs='kubectl delete service'
+alias krap='kubectl delete all --all -n'
+
+# Edit and Apply Aliases
+alias kec='kubectl edit configmap'
+alias kaf='kubectl apply -f'
+alias krf='kubectl delete -f'
+alias ked='kubectl edit deployment'
+
+# Logging and Monitoring
+alias kgl='kubectl logs -f'
+alias kwp='kubectl logs -f'
+alias wkga='watch kubectl get all'
+alias wkgp='watch kubectl get pods'
+alias ktn='kubectl top nodes'
+alias ktp='kubectl top pods'
+alias ktpm='kubectl top pods --sort-by=memory'
+alias ktpc='kubectl top pods --sort-by=cpu'
+
+# Namespace and Context Management
+alias ksn='kubectl config set-context --current --namespace'
+alias ksxh='set KUBECONFIG ~/.kube/config-hogwarts'
+alias ksxg='set KUBECONFIG ~/.kube/config-gondor'
+alias ksx='kubectl config use-context'
+alias kgx='kubectl config get-contexts'
+alias kcx='kubectl config use-context'
+
+# Scaling and Pause
+alias kp='kubectl scale deployment --replicas=0'
+alias kr='kubectl scale deployment --replicas=1'
+alias kts='talosctl shutdown -n'
+alias ktr='talosctl reboot -n'
+
+# Advanced Helpers
+alias kdp='kubectl describe pods'
+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
+alias kdd='kubectl describe deployments'
+alias kdn='kubectl describe nodes'
+alias random='openssl rand -hex'
+
+function kgd # this will only work with pbcopy installed
+ # Get current namespace
+ set namespace (kubectl config view --minify --output 'jsonpath={..namespace}')
+
+ # Get all services in the current namespace
+ set services (kubectl get services -o name | sed 's/service\///')
+
+ # Check if any services exist
+ if test (count $services) -eq 0
+ echo "No services found in namespace: $namespace"
+ return 1
+ end
+
+ # If there's only one service, automatically select it
+ if test (count $services) -eq 1
+ set selected_service $services[1]
+ set selection 1
+ else
+ # Display services with numbers
+ echo "Select a service from namespace '$namespace':"
+ for i in (seq (count $services))
+ echo "$i. $services[$i]"
+ end
+
+ # Get user selection
+ read -P "Enter selection number: " selection
+ end
+
+ # Validate selection
+ if test "$selection" -ge 1 -a "$selection" -le (count $services)
+ set selected_service $services[$selection]
+
+ # Get the port for the selected service
+ set port_data (kubectl get service $selected_service -o jsonpath='{.spec.ports[0].port}')
+
+ # Create the URL with port
+ set url "$selected_service.$namespace.svc.cluster.local:$port_data"
+
+ # Output the result
+ echo $url
+
+ # Copy to clipboard if pbcopy/xclip is available
+ if type -q pbcopy
+ echo $url | pbcopy
+ echo "URL copied to clipboard!"
+ else if type -q xclip
+ echo $url | xclip -selection clipboard
+ echo "URL copied to clipboard!"
+ end
+ else
+ echo "Invalid selection!"
+ return 1
+ end
+end
+
+function tkgd
+ # Get current namespace
+ set namespace (tsh kubectl config view --minify --output 'jsonpath={..namespace}')
+
+ # Get all services in the current namespace
+ set services (tsh kubectl get services -o name | sed 's/service\///')
+
+ # Check if any services exist
+ if test (count $services) -eq 0
+ echo "No services found in namespace: $namespace"
+ return 1
+ end
+
+ # Display services with numbers
+ echo "Select a service from namespace '$namespace':"
+ for i in (seq (count $services))
+ echo "$i. $services[$i]"
+ end
+
+ # Get user selection
+ read -P "Enter selection number: " selection
+
+ # Validate selection
+ if test "$selection" -ge 1 -a "$selection" -le (count $services)
+ set selected_service $services[$selection]
+
+ # Create the URL
+ set url "$selected_service.$namespace.svc.cluster.local"
+
+ # Output the result
+ echo $url
+
+ # Copy to clipboard if pbcopy/xclip is available
+ if type -q pbcopy
+ echo $url | pbcopy
+ echo "URL copied to clipboard!"
+ else if type -q xclip
+ echo $url | xclip -selection clipboard
+ echo "URL copied to clipboard!"
+ end
+ else
+ echo "Invalid selection!"
+ return 1
+ end
+end
+
+## These are duplicates of the above but using teleport to connect to the cluster
+
+# --- Kubectl Aliases ---
+alias tk='tsh kubectl'
+
+# Resource Management Aliases
+alias tkgp='tsh kubectl get pods'
+alias tkgpw='tsh kubectl get pods -o wide --sort-by=".spec.nodeName"'
+alias tkga='tsh kubectl get all'
+alias tkgn='tsh kubectl get namespaces'
+alias tkgi='tsh kubectl get ingress'
+alias tkgc='tsh kubectl get configmaps'
+alias tkgs='tsh kubectl get services'
+alias tkgss='tsh kubectl get statefulsets'
+
+# Create Aliases
+alias tkcc='tsh kubectl create configmap'
+alias tkcn='tsh kubectl create namespace'
+alias tkcd='tsh kubectl create deployment'
+
+# Delete/Remove Aliases
+alias tkrp='tsh kubectl delete'
+alias tkrc='tsh kubectl delete configmap'
+alias tkri='tsh kubectl delete ingress'
+alias tkrn='tsh kubectl delete namespace'
+alias tkrd='tsh kubectl delete deployment'
+alias tkrs='tsh kubectl delete service'
+alias tkrap='tsh kubectl delete all --all -n'
+
+# Edit and Apply Aliases
+alias tkec='tsh kubectl edit configmap'
+alias tkaf='tsh kubectl apply -f'
+alias tkrf='tsh kubectl delete -f'
+alias tked='tsh kubectl edit deployment'
+
+# Logging and Monitoring
+alias tkgl='tsh kubectl logs -f'
+alias tkwp='tsh kubectl logs -f'
+alias twkga='watch tsh kubectl get all'
+alias twkgp='watch tsh kubectl get pods'
+alias tktn='tsh kubectl top nodes'
+alias tktp='tsh kubectl top pods'
+alias tktpm='tsh kubectl top pods --sort-by=memory'
+alias tktpc='tsh kubectl top pods --sort-by=cpu'
+
+# Namespace and Context Management
+alias tksn='tsh kubectl config set-context --current --namespace'
+alias tksxh='tsh kube login hogwarts'
+alias tksxg='tsh kube login gondor'
+alias tksx='tsh kubectl config use-context'
+alias tkgx='tsh kubectl config get-contexts'
+alias tkcx='tsh kubectl config use-context'
+
+# Scaling and Pause
+alias tkp='tsh kubectl scale deployment --replicas=0'
+alias tkr='tsh kubectl scale deployment --replicas=1'
+alias tkts='talosctl shutdown -n'
+alias tktr='talosctl reboot -n'
+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
+
+# Advanced Helpers
+alias tkdp='tsh kubectl describe pods'
+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
+alias tkdd='tsh kubectl describe deployments'
+alias tkdn='tsh kubectl describe nodes'
+
+# --- Kubernetes Helper Aliases (Fish Function) ---
+
+function kh
+ clear
+ # Guidance for Customization
+ printf "\033[0;31mYou can modify these aliases in ~/.config/fish/config.fish\033[0m\n\n"
+
+ # Basic Aliases
+ printf "\033[0;32mBasic Aliases\033[0m\n"
+ printf "\033[0;34mk\033[0m - Short for 'kubectl'\n"
+ printf "\033[0;34mkh\033[0m - Display this help and list all aliases\n\n"
+
+ # Resource Management
+ printf "\033[0;32mResource Management\033[0m\n"
+ printf "\033[0;34mkgp\033[0m - Get pods in current namespace\n"
+ printf "\033[0;34mkgpw\033[0m - Get pods with wide details, sorted by node\n"
+ printf "\033[0;34mkga\033[0m - Get all resources in current namespace\n"
+ printf "\033[0;34mkgn\033[0m - Get namespaces\n"
+ printf "\033[0;34mkgi\033[0m - Get ingress in current namespace\n"
+ printf "\033[0;34mkgc\033[0m - Get configmaps in current namespace\n"
+ printf "\033[0;34mkgd\033[0m - Get deployments\n"
+ printf "\033[0;34mkgss\033[0m - Get statefulsets\n\n"
+
+ # Creating Resources
+ printf "\033[0;32mCreating Resources\033[0m\n"
+ printf "\033[0;34mkcc\033[0m - Create a configmap\n"
+ printf "\033[0;34mkcn\033[0m - Create a namespace\n"
+ printf "\033[0;34mkcd\033[0m - Create a deployment\n\n"
+
+ # Deleting/Removing
+ printf "\033[0;32mDeleting/Removing\033[0m\n"
+ printf "\033[0;34mkrp\033[0m - Remove a pod\n"
+ printf "\033[0;34mkrc\033[0m - Remove a configmap\n"
+ printf "\033[0;34mkrd\033[0m - Remove a deployment\n"
+ printf "\033[0;34mkrs\033[0m - Remove a service\n"
+ printf "\033[0;34mkrn\033[0m - Remove a namespace\n"
+ printf "\033[0;34mkrp\033[0m - Remove a pod\n\n"
+
+ # Editing and Applying
+ printf "\033[0;32mEditing and Applying\033[0m\n"
+ printf "\033[0;34mkec\033[0m - Edit a configmap\n"
+ printf "\033[0;34mraft\033[0m - Apply file to current namespace\n"
+ printf "\033[0;34mkaf\033[0m - Edit a deployment\n\n"
+
+ # Logging and Monitoring
+ printf "\033[0;32mLogging and Monitoring\033[0m\n"
+ printf "\033[0;34mkgl\033[0m - Get logs\n"
+ printf "\033[0;34mkwp\033[0m - Watch logs of a pod\n"
+ printf "\033[0;34mktn\033[0m - Get node usage stats\n"
+ printf "\033[0;34mktp\033[0m - Get pod usage stats\n"
+ printf "\033[0;34mktpc\033[0m - Pod stats sorted by CPU\n\n"
+
+ # Namespace and Context
+ printf "\033[0;32mNamespace and Context\033[0m\n"
+ printf "\033[0;34mksn\033[0m - Set current namespace\n"
+ printf "\033[0;34mksx\033[0m - Set current context\n"
+ printf "\033[0;34mksxh\033[0m - Switch context to Hogwarts\n"
+ printf "\033[0;34mksxg\033[0m - Switch context to Gondor\n"
+ printf "\033[0;34mkgx\033[0m - Get contexts (namespaces)\n\n"
+
+ # Scaling and Pause
+ printf "\033[0;32mScaling and Pause\033[0m\n"
+ printf "\033[0;34mkp\033[0m - Pause a pod/deployment (scale to 0)\n"
+ printf "\033[0;34mkr\033[0m - Resume a deployment (scale to 1)\n\n"
+
+ # Advanced Helpers
+ printf "\033[0;32mAdvanced Helpers\033[0m\n"
+ printf "\033[0;34mkdp\033[0m - Describe pods\n"
+ printf "\033[0;34mkdd\033[0m - Describe deployments\n"
+ printf "\033[0;34mkdn\033[0m - Describe nodes\n\n"
+
+ # Additional Commands
+ printf "\033[0;31mAdditional Commands\033[0m\n"
+ printf "\033[0;34mrandom\033[0m - Create a random string\n"
+ printf "\033[0;34mdash\033[0m - Show Talos Dashboard\n"
+ printf "kubectl create secret generic my-secret --from-literal=username=admin\n"
+ printf "random 32\n"
+ printf "helm show values openebs/openebs > values-openebs.yaml\n"
+ printf "Add 't' to the beginning of any alias to use teleport\n"
+ printf "\033[0;34tr\033[0m - Reboot all Nodes"
+ printf "\033[0;34ts\033[0m - Shutdown all Nodes"
+end
+
+```
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9