Changing the default k9s/Kubernetes context
Asked Answered
A

3

12

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?

Aubergine answered 19/5, 2022 at 11:58 Comment(0)
E
14

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.

Exodontist answered 19/5, 2022 at 12:27 Comment(0)
S
1

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

Semiotics answered 4/4 at 7:22 Comment(0)
D
0

I think you can change the k9s config.yml file, this link can help you understand better https://k9scli.io/topics/config, normally it is defined like this example:

k9s:
  refreshRate: 2
  maxConnRetry: 5
  enableMouse: false
  headless: false
  logoless: false
  crumbsless: false
  readOnly: false
  noExitOnCtrlC: false
  noIcons: false
  logger:
    tail: 100
    buffer: 5000
    sinceSeconds: 60
    fullScreenLogs: false
    textWrap: false
    showTime: false
  **currentContext**: arn:aws:eks:us-east-1:ID:cluster/account-name
  **currentCluster**: arn:aws:eks:us-east-1:ID:cluster/account-name
Dirtcheap answered 24/2, 2023 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.