kubectx & kubens: Quick Start

This post shows examples of kubectx & kubens.


install

% brew install kubectx

This will install both kubectx and kubens.


kubectx

kubectx help manage k8s contexts.

% kubectx -h

USAGE:
  kubectx                       : list the contexts
  kubectx <NAME>                : switch to context <NAME>
  kubectx -                     : switch to the previous context
  ...


Listing the contexts is as simple as follows:

% kubectl config get-contexts

CURRENT   NAME        CLUSTER     AUTHINFO    NAMESPACE
*         kind-kind   kind-kind   kind-kind   
          minikube    minikube    minikube    default

% kubectx

kind-kind
minikube


Change the context:

% kubectx minikube

Switched to context "minikube".

% kubectx         

kind-kind

minikube

% kubectx -

Switched to context "kind-kind".

% kubectx  

kind-kind

minikube


kubens

kubens help manage k8s namaepaces (ns).

% kubens -h     

USAGE:
  kubens                    : list the namespaces in the current context
  kubens <NAME>             : change the active namespace of current context
  kubens -                  : switch to the previous namespace in this context
  ...


Here is the comparizon between kubectl and kubens:

% kubectl get ns

NAME                 STATUS   AGE
default              Active   4m11s
kube-node-lease      Active   4m12s
kube-public          Active   4m12s
kube-system          Active   4m12s
local-path-storage   Active   4m6s

% kubens        

default
kube-node-lease
kube-public
kube-system
local-path-storage


Change the namespaces:

% kubens kube-system

Context "kind-kind" modified.
Active namespace is "kube-system".
% kubens            
default
kube-node-lease
kube-public
kube-system
local-path-storage

% kubens -

Context "kind-kind" modified.
Active namespace is "default".

% kubens  

default
kube-node-lease
kube-public
kube-system
local-path-storage


Comments

Popular posts from this blog

Minikube Installation for M1 Mac

Selenide: Quick Start

PyCharm: Quick Start