kubea(){
if [ "$#" = 1 ]; then
KUBECONFIG=~/.kube/configs/"$1"
else
ls -1 ~/.kube/configs/
fi
}
That way I can "activate" a specific config the same way I activate my Python virtualenv, for a specific terminal. I also add the basename of the config to my prompt.
I've always been confused with kubectx. How do I actually add a seperate yaml file (say the one I download with my browser from DigitalOcean) into the context?
Or you can signify the context using shell prompt and use kube rbac to give read only permissions instead of letting people mess with your prod cluster.
kube-ps1, kubectx and kubens can help quite a bit here. kube-ps1 to give you a visual indication of current context and the others to make switching easier.
You can also explicitly add namespaces to manifests, which help avoid applying to the wrong namespace.
Agreed. With autocomplete I find myself being able to make those long commands painless while making sure I'm being explicit. Only took me one time running the wrong command against the wrong cluster to drill that one into my brain forever haha
I like to have one config file per cluster and point kubeconfig to all these files. Then I use a bash function to select the cluster by name. My zsh shell previews the cluster name on the right when I start typing k, kubectl, helm and similar... So it is harder for me to make a mistake
It's a mixed bag. On one hand it's a pain when you have to switch back and forth. On the other hand it's awesome that all the state is in one, human-readable file and can easily be duplicated or pointed somewhere else, etc.
I primarily use OpenShift which fixes part of it, and with a few bash aliases the rest are pretty painless as well.
Super annoying why ever have very specific way to merge multiple contexts. Google utils writes to this file one way, other tools another way. So weird and so not-transparent.
[+] [-] kissgyorgy|5 years ago|reply
[+] [-] remram|5 years ago|reply
[+] [-] neximo64|5 years ago|reply
[+] [-] echelon|5 years ago|reply
[+] [-] mlthoughts2018|5 years ago|reply
You should absolutely always be typing out huge, verbose commands like kubectl —context my-context -n my-namespace <some commands> ...
The opportunity for tragic error when you have implicit context or namespace settings applied is just too great.
[+] [-] longcommonname|5 years ago|reply
[+] [-] rtempaccount1|5 years ago|reply
You can also explicitly add namespaces to manifests, which help avoid applying to the wrong namespace.
[+] [-] joeskyyy|5 years ago|reply
[+] [-] jaimehrubiks|5 years ago|reply
[+] [-] mastegizmo|5 years ago|reply
[+] [-] jml78|5 years ago|reply
[+] [-] unknown|5 years ago|reply
[deleted]
[+] [-] pepemon|5 years ago|reply
[1] https://kubernetes.io/docs/tasks/access-application-cluster/...
[+] [-] nunez|5 years ago|reply
[+] [-] freedomben|5 years ago|reply
I primarily use OpenShift which fixes part of it, and with a few bash aliases the rest are pretty painless as well.
[+] [-] pgwhalen|5 years ago|reply
[+] [-] ex3ndr|5 years ago|reply
[+] [-] anurag|5 years ago|reply