Created
September 9, 2025 06:11
-
-
Save knutole/89a706d1f2160e284e137b985babdc76 to your computer and use it in GitHub Desktop.
Helper script for ohmyzsh kubectl aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # kubectl-alias-help - Colorful help screen for kubectl aliases | |
| # Color definitions | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| BLUE='\033[0;34m' | |
| MAGENTA='\033[0;35m' | |
| CYAN='\033[0;36m' | |
| BOLD='\033[1m' | |
| NC='\033[0m' # No Color | |
| # Header function | |
| print_header() { | |
| echo -e "${BOLD}${GREEN}=========================================================${NC}" | |
| echo -e "${BOLD}${GREEN} KUBECTL ALIAS HELP SCREEN${NC}" | |
| echo -e "${BOLD}${GREEN}=========================================================${NC}" | |
| echo | |
| } | |
| # Section function | |
| print_section() { | |
| echo -e "${BOLD}${BLUE}$1${NC}" | |
| echo -e "${BOLD}${BLUE}---------------------------------------------------------${NC}" | |
| } | |
| # Warning function | |
| print_warning() { | |
| echo -e "${RED}⚠ $1${NC}" | |
| } | |
| # Short help version | |
| show_short_help() { | |
| # print_header | |
| # echo -e "${BOLD}Quick reference for the most important kubectl aliases${NC}" | |
| # echo | |
| echo | |
| print_section "BASIC COMMANDS" | |
| echo -e "${BOLD}${CYAN}k ${NC}kubectl The kubectl command" | |
| echo -e "${BOLD}${CYAN}kca ${NC}kubectl --all-namespaces Target all namespaces" | |
| echo -e "${BOLD}${CYAN}kaf ${NC}kubectl apply -f Apply a YML file" | |
| echo -e "${BOLD}${CYAN}keti ${NC}kubectl exec -ti Interactive terminal on container" | |
| echo | |
| print_section "NAMESPACE MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgns ${NC}kubectl get namespaces List namespaces" | |
| echo -e "${BOLD}${CYAN}kcn ${NC}kubectl config set-context... Change current namespace" | |
| echo -e "${BOLD}${CYAN}kdelns ${NC}kubectl delete namespace Delete namespace ${RED}(DANGER)${NC}" | |
| echo | |
| print_section "POD MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgp ${NC}kubectl get pods List all pods" | |
| echo -e "${BOLD}${CYAN}kgpn ${NC}kgp -n Get pods by namespace" | |
| echo -e "${BOLD}${CYAN}kdp ${NC}kubectl describe pods Describe pods" | |
| echo -e "${BOLD}${CYAN}kl ${NC}kubectl logs Print logs" | |
| echo -e "${BOLD}${CYAN}klf ${NC}kubectl logs -f Stream logs (follow)" | |
| echo | |
| print_section "SERVICE MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgs ${NC}kubectl get svc List services" | |
| echo -e "${BOLD}${CYAN}kds ${NC}kubectl describe svc Describe services" | |
| echo | |
| print_section "DEPLOYMENT MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgd ${NC}kubectl get deployment Get deployments" | |
| echo -e "${BOLD}${CYAN}kdd ${NC}kubectl describe deployment Describe deployments" | |
| echo -e "${BOLD}${CYAN}ksd ${NC}kubectl scale deployment Scale deployment" | |
| echo | |
| print_section "CONTEXT & CONFIG" | |
| echo -e "${BOLD}${CYAN}kcuc ${NC}kubectl config use-context Switch context" | |
| echo -e "${BOLD}${CYAN}kccc ${NC}kubectl config current-context Show current context" | |
| echo -e "${BOLD}${CYAN}kcgc ${NC}kubectl config get-contexts List available contexts" | |
| echo | |
| echo -e "Use ${BOLD}${MAGENTA}kh long${NC} for the complete alias list" | |
| echo | |
| } | |
| # Long help version | |
| show_long_help() { | |
| print_header | |
| echo -e "${BOLD}Complete reference for all kubectl aliases${NC}" | |
| echo | |
| print_section "BASIC KUBECTL COMMANDS" | |
| echo -e "${BOLD}${CYAN}k ${NC}kubectl The kubectl command" | |
| echo -e "${BOLD}${CYAN}kca ${NC}kubectl --all-namespaces The kubectl command targeting all namespaces" | |
| echo -e "${BOLD}${CYAN}kaf ${NC}kubectl apply -f Apply a YML file" | |
| echo -e "${BOLD}${CYAN}keti ${NC}kubectl exec -ti Drop into an interactive terminal on a container" | |
| print_section "CONFIGURATION & CONTEXT MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kcuc ${NC}kubectl config use-context Set the current-context in a kubeconfig file" | |
| echo -e "${BOLD}${CYAN}kcsc ${NC}kubectl config set-context Set a context entry in kubeconfig" | |
| echo -e "${BOLD}${CYAN}kcdc ${NC}kubectl config delete-context Delete the specified context from the kubeconfig" | |
| echo -e "${BOLD}${CYAN}kccc ${NC}kubectl config current-context Display the current-context" | |
| echo -e "${BOLD}${CYAN}kcgc ${NC}kubectl config get-contexts List of contexts available" | |
| print_section "GENERAL ALIASES" | |
| echo -e "${BOLD}${CYAN}kdel ${NC}kubectl delete Delete resources" | |
| echo -e "${BOLD}${CYAN}kdelf ${NC}kubectl delete -f Delete using type and name from -f argument" | |
| echo -e "${BOLD}${CYAN}kge ${NC}kubectl get events --sort-by... Get events (sorted by timestamp)" | |
| echo -e "${BOLD}${CYAN}kgew ${NC}kubectl get events --watch... Get events and watch as they occur" | |
| print_section "POD MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgp ${NC}kubectl get pods List all pods in ps output format" | |
| echo -e "${BOLD}${CYAN}kgpl ${NC}kgp -l Get pods by label" | |
| echo -e "${BOLD}${CYAN}kgpn ${NC}kgp -n Get pods by namespace" | |
| echo -e "${BOLD}${CYAN}kgpsl ${NC}kubectl get pods --show-labels List pods with labels" | |
| echo -e "${BOLD}${CYAN}kgpw ${NC}kgp --watch Watch for changes after listing" | |
| echo -e "${BOLD}${CYAN}kgpwide${NC}kgp -o wide Output with additional information" | |
| echo -e "${BOLD}${CYAN}kep ${NC}kubectl edit pods Edit pods from the default editor" | |
| echo -e "${BOLD}${CYAN}kdp ${NC}kubectl describe pods Describe all pods" | |
| echo -e "${BOLD}${CYAN}kdelp ${NC}kubectl delete pods Delete all pods matching passed arguments" | |
| print_section "SERVICE MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgs ${NC}kubectl get svc List all services in ps output format" | |
| echo -e "${BOLD}${CYAN}kgsw ${NC}kgs --watch Watch for changes after listing services" | |
| echo -e "${BOLD}${CYAN}kgswide${NC}kgs -o wide Output with additional information" | |
| echo -e "${BOLD}${CYAN}kes ${NC}kubectl edit svc Edit services from the default editor" | |
| echo -e "${BOLD}${CYAN}kds ${NC}kubectl describe svc Describe all services in detail" | |
| echo -e "${BOLD}${CYAN}kdels ${NC}kubectl delete svc Delete all services matching passed argument" | |
| print_section "INGRESS MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgi ${NC}kubectl get ingress List ingress resources" | |
| echo -e "${BOLD}${CYAN}kei ${NC}kubectl edit ingress Edit ingress resource" | |
| echo -e "${BOLD}${CYAN}kdi ${NC}kubectl describe ingress Describe ingress resource in detail" | |
| echo -e "${BOLD}${CYAN}kdeli ${NC}kubectl delete ingress Delete ingress resources" | |
| print_section "NAMESPACE MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgns ${NC}kubectl get namespaces List the current namespaces in a cluster" | |
| echo -e "${BOLD}${CYAN}kcn ${NC}kubectl config set-context... Change current namespace" | |
| echo -e "${BOLD}${CYAN}kens ${NC}kubectl edit namespace Edit namespace resource" | |
| echo -e "${BOLD}${CYAN}kdns ${NC}kubectl describe namespace Describe namespace resource in detail" | |
| echo -e "${BOLD}${CYAN}kdelns ${NC}kubectl delete namespace ${RED}Delete the namespace (WARNING!)${NC}" | |
| print_section "DEPLOYMENT MANAGEMENT" | |
| echo -e "${BOLD}${CYAN}kgd ${NC}kubectl get deployment Get the deployment" | |
| echo -e "${BOLD}${CYAN}kgdw ${NC}kgd --watch Watch for changes after getting deployment" | |
| echo -e "${BOLD}${CYAN}kgdwide${NC}kgd -o wide Output with additional information" | |
| echo -e "${BOLD}${CYAN}ked ${NC}kubectl edit deployment Edit deployment resource" | |
| echo -e "${BOLD}${CYAN}kdd ${NC}kubectl describe deployment Describe deployment resource in detail" | |
| echo -e "${BOLD}${CYAN}kdeld ${NC}kubectl delete deployment Delete the deployment" | |
| echo -e "${BOLD}${CYAN}ksd ${NC}kubectl scale deployment Scale a deployment" | |
| echo -e "${BOLD}${CYAN}krsd ${NC}kubectl rollout status... Check rollout status of a deployment" | |
| echo -e "${BOLD}${CYAN}kres ${NC}kubectl set env... Recreate pods with zero-downtime" | |
| print_section "LOGS" | |
| echo -e "${BOLD}${CYAN}kl ${NC}kubectl logs Print the logs for a container or resource" | |
| echo -e "${BOLD}${CYAN}klf ${NC}kubectl logs -f Stream the logs for a container or resource (follow)" | |
| print_section "TOOLS FOR ACCESSING ALL INFORMATION" | |
| echo -e "${BOLD}${CYAN}kga ${NC}kubectl get all List all resources in ps format" | |
| echo -e "${BOLD}${CYAN}kgaa ${NC}kubectl get all --all-namespaces List objects across all namespaces" | |
| print_section "PORT FORWARDING" | |
| echo -e "${BOLD}${CYAN}kpf ${NC}kubectl port-forward Forward local ports to a pod" | |
| print_section "FILE COPY" | |
| echo -e "${BOLD}${CYAN}kcp ${NC}kubectl cp Copy files to and from containers" | |
| print_warning "Be careful with delete commands, especially for namespaces and nodes!" | |
| echo | |
| } | |
| # Display help based on arguments | |
| case "${1:-short}" in | |
| -s|--short|short) | |
| show_short_help | |
| ;; | |
| -l|--long|long) | |
| show_long_help | |
| ;; | |
| -h|--help|help) | |
| echo -e "${BOLD}Usage:${NC}" | |
| echo -e " kh ${GREEN}Show short help (default)${NC}" | |
| echo -e " kh long ${GREEN}Show complete help with all aliases${NC}" | |
| echo -e " kh --help ${GREEN}Show this help message${NC}" | |
| echo | |
| ;; | |
| *) | |
| echo -e "${RED}Unknown option: $1${NC}" | |
| echo -e "Use ${BOLD}kh --help${NC} for usage information" | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment