#!/usr/bin/env bash # 40_k8s.sh — Kubernetes / kubectl aliases and completion # # Loaded on all machines but only meaningful on work hosts. # kubectl must be installed for completion to activate. # ============================================================================ command -v kubectl >/dev/null 2>&1 || return 0 # skip silently if not installed # Bash completion source <(kubectl completion bash) alias k=kubectl complete -o default -F __start_kubectl k # Config inspection alias kc='kubectl config view' alias kuc='kubectl config use-context' # Resource shortcuts alias kd='kubectl describe' alias ke='kubectl explain' alias kg='kubectl get' alias kl='kubectl logs -f' alias kp='kubectl get pods -o wide' alias kq='kubectl describe quota' alias ks='kubectl get services' alias kpl='kubectl get pods --show-labels' alias kdp='kubectl describe pod' alias kgs='kubectl get secrets' # Context / namespace switchers alias kx='f() { [ "$1" ] && kubectl config use-context "$1" || kubectl config current-context; }; f' alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace "$1" || kubectl config view --minify | grep namespace | cut -d" " -f6; }; f'