Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default k9s/Kubernetes context

I have 3 contexts set up in k9s (context1, context2, context3). I know I can change the context within k9s by typing :context but how do I change the default context that loads when I open k9s from context3 to context1?

like image 656
Bhav Avatar asked Mar 10 '26 22:03

Bhav


2 Answers

You can set the default context via kubectl:

kubectl config use-context context1

This will update the default context in your KUBECONFIG, what is the base for k9s.

like image 130
chresse Avatar answered Mar 12 '26 11:03

chresse


From your commandline (not inside k9s) you should be able to use kubectl as k9s needs it.

  1. get a list of the contexts: kubectl config get-contexts
  2. set the default contexts: kubectl config use-context <context>

Example shell

$ kubectl config get-contexts
CURRENT   NAME       CLUSTER   AUTHINFO    NAMESPACE
          dev        dev       dev    
*         test       test      test
          my-context idk       idk
$ kubectl config use-context my-context
Switched to context "my-context".
$ kubectl config get-contexts
CURRENT   NAME       CLUSTER   AUTHINFO    NAMESPACE
          dev        dev       dev    
          test       test      test
*         my-context idk       idk
$

Now you see the star on CURRENT on a different value

like image 36
Remi Kristelijn Avatar answered Mar 12 '26 10:03

Remi Kristelijn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!