-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to increase productivity with kubectl, using multiple namespaces per context #1
base: master
Are you sure you want to change the base?
Conversation
in order to produce a PS1 in ~/.bash_profile I failed to find an elegant solution for such needs.
I ended up doing, in my ~/.bash_profile: # TODO how do I get bash completion to work for kubectl aliases?
alias k="kubectl"
kcfg() {
KCFG="${1}"
# keep config names short and you won't need tab completion :)
[ ! -f "$KCFG" ] && [ -f "$HOME/.kube/$KCFG" ] && KCFG="$HOME/.kube/$KCFG"
export KUBECONFIG="$KCFG"
namespaces=$(kubectl --request-timeout 3 get namespace -o jsonpath="{.items[*].metadata.name}")
[ $? -eq 0 ] && {
echo -n "Aliases for $(basename $KUBECONFIG):"
for namespace in $namespaces
do
# https://github.com/kubernetes/kubernetes/pull/23262
alias k-$namespace="kubectl --namespace $namespace"
echo -n ", k-$namespace"
done
echo ""
}
} Works nicely with a prompt: export PS1="\u@\h\[\033[34m\]\$(basename \"\$KUBECONFIG\")\[\033[00m\] \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ " Assumption: default config (~/.kube/config) is never a production cluster -- you must explicitly select those per shell. |
These aliases have really helped. I should take another look at https://github.com/ahmetb/kubectl-aliases. |
Yolean/kubernetes-kafka#84 (comment) is worth an alias too |
I'd like to merge this with atamon/kube-cluster-alias#1 |
Please let me know which parts. Maybe we should transfer the result to the Yolean organization too I guess? I'm quite happy with atamon/kube-cluster-alias#1 after running it a while now. So I'm merging it now :) |
There's quite some activity in this area, but I found nothing with the proper level of respect for what it means that context is per-user, not per shell. You normally have dev, qa and prod clusters.
Not even if the context name is displayed in your shell prompt will you be properly warned from doing something dev-ish in prod: the prompt may be old - you might be hopping between terminal tabs.