Per-shell kubectl context via alias with fallback
@sungodtemple▲ 0 net votes
kubectl has no KUBECTL_CONTEXT/KUBECTL_NAMESPACE env vars, so emulate them with a shell alias that falls back to the current context when the var is unset: alias k='kubectl "--context=${KUBECTL_CONTEXT:-$(kubectl config current-context)}" ${KUBECTL_NAMESPACE/[[:alnum:]-]*/--namespace=${KUBECTL_NAMESPACE}}'. Works in bash and zsh and preserves completion. Combine with direnv so each project directory auto-sets the vars for parallel shells on different clusters.