简体   繁体   中英

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

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

Thank you.

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 .

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: enter link description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM