Tips and Tricks: Switch K8S Namespace

Friday, Sep 24, 2021 16:00 · 126 words · 1 minute read

Tips and Tricks

  1. K8S Context Commands
  2. Manually Allocate Elasticsearch Shards
  3. Switch K8S Namespace
  4. Tail Logs in K8S

Overview

In this blog post I will demonstrate how to check the current namespace for your current K8S context and how to switch to different one.

Solution

What is my current K8S namespace ?

kubectl config view --minify --output 'jsonpath={..namespace}'; echo
Output:
default

or

kubectl config get-contexts
Output:
CURRENT   NAME               CLUSTER            AUTHINFO                                           NAMESPACE
          dev-k8s            dev-k8s            clusterUser_dev-k8s                                apps
*         minikube           minikube           minikube                                           default

Switch to different K8S namespace

kubectl config set-context --current --namespace=tracing
Output:
Context "minikube" modified.

Double check the current context

kubectl config view --minify --output 'jsonpath={..namespace}'; echo
Output:
tracing

or

kubectl config get-contexts
Output:
CURRENT   NAME               CLUSTER            AUTHINFO                                           NAMESPACE
          dev-k8s            dev-k8s            clusterUser_dev-k8s                                apps
*         minikube           minikube           minikube                                           tracing
comments powered by Disqus