8

I'm new to Kubernetes and wondering, if there's a kubectl command to figure out what namespace I'm currently working in?

Running the kubectl get ns command prints out all the namespaces but doesn't show which one I'm in at present.

Jonas
  • 121,568
  • 97
  • 310
  • 388
Metro
  • 873
  • 8
  • 19
  • Does this answer your question? [How to switch namespace in kubernetes](https://stackoverflow.com/questions/55373686/how-to-switch-namespace-in-kubernetes) – Jehof Jun 02 '21 at 20:12

2 Answers2

11

You want to inspect the local config for kubectl and see current context. This shows your current context with namespace.

kubectl config get-contexts 

Example output - can also be multiple clusters, but only one "current":

$kubectl config get-contexts   
CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE    
*         minikube   minikube   minikube   default
Jonas
  • 121,568
  • 97
  • 310
  • 388
4

kubectl config get-contexts

Should give you what you need.

Hammed
  • 1,457
  • 1
  • 24
  • 37