Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes. Is it possible to configure a default namespace for a user?

Tags:

kubernetes

Is it possible to configure a default namespace (other than "default") for a user in kubernetes?

Thank you.

like image 717
Jxadro Avatar asked Oct 25 '17 07:10

Jxadro


2 Answers

Yes, just set .contexts[].context.namespace in the kubeconfig file of the user.

You can do that manually with a text editor (~/.kube/config):

apiVersion: v1
clusters:
...
contexts:
- context:
    cluster: development
    namespace: frontend
    user: developer
  name: dev-frontend
current-context: dev-frontend
kind: Config
preferences: {}
users:
...

Or with kubectl config. This example sets the namespace to frontend in the current context:

kubectl config set "contexts."`kubectl config current-context`".namespace" frontend

For more details and explanation see this document.

like image 73
Janos Lenart Avatar answered Oct 07 '22 02:10

Janos Lenart


Set namespace to current-context with:
kubectl config set-context --current --namespace=my-namespace or
kubectl config set-context $(kubectl config current-context) --namespace=<namespace>

Check whether it is set or not with:
kubectl config view | grep namespace:

ref:kubectl cheatsheet

like image 21
AATHITH RAJENDRAN Avatar answered Oct 07 '22 02:10

AATHITH RAJENDRAN