Kubernetes. Is it possible to configure a default namespace for a user?
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
orkubectl 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