0

This is kind of a silly one but, given a number of clusters...

How would a user specify one cluster to be set as the default?

CURRENT  NAME
*        minikube   
         stage     
         prod      

Every time I open a new Terminal (macOS), it defaults to prod. I know I'm just one misstep away from not paying attention and destroying something valuable.

  • If I set minikube as the current cluster, then open new tabs in the same Terminal window, minikube remains the default.
  • If I were to Quit the Terminal altogether and reopen it, it would default back to prod.

Anecdotally, I've used ktx forever and never had this issue. Recently tried kubectx and this is the first time I've noticed the behavior. I don't see anything in their docs about setting a default cluster so seems unlikely.

If anyone knows how to set a default cluster, please advise.

todd_dsm
  • 918
  • 1
  • 14
  • 21
  • These configs are written to ~/.kube/config file. So it is possible that when you restart your terminal and bash_profile or bashrc files (depending on your shell) are executed, they are somehow changing that config file. – saurabh_garg Aug 02 '22 at 07:12

1 Answers1

0

If you use kubectl, the command kubectl config use-context might help. In your case :

kubectl config use-context minikube
  • that changes it for sure; what I can't understand is *after* I change it, then Quit/reopen the Terminal, why it changes back to the prod cluster. – todd_dsm Aug 01 '22 at 22:31
  • Does your ~/.kube/config contains `current-context: prod` ? Do you use the correct kubeconfig ? – Samuel Bagattin Aug 02 '22 at 21:46
  • I've changed it to minikube (again), but yes; I grep'd for `current-context` and found minikube designated. – todd_dsm Aug 02 '22 at 22:14
  • With the right value set of current-context, you should have kubectl defaulting to minikube. If this is not the case, try to specify explicitely your kubeconfig with `kubectl --kubeconfig ~/.kube/config`. Make sure as well that `kubectl config current-context` outputs the right context. – Samuel Bagattin Aug 03 '22 at 21:43