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