user5024478
user5024478

Reputation:

kubernetes: How to set active namespace for all kubectl commands?

I am working on kubernetes cluster. In my cluster i am having 3 namespaces.

At a time when i want to work on staging namespace.

In every kubectl command i have to pass namespace

kubectl get pods -n staging

kubectl get deployment -n staging

Is there any way to set active namespace at a time?

Upvotes: 4

Views: 8893

Answers (3)

Mahdi Shirazi
Mahdi Shirazi

Reputation: 9

you can edit any config with this command :

kubectl edit configmaps

edit namespace.

Upvotes: -1

hariK
hariK

Reputation: 3069

kubectl config set-context --current --namespace=<insert-namespace-name-here>

Refer here

Also you can use kubectx plugin

Upvotes: 5

hoque
hoque

Reputation: 6471

kubectl config set-context --current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view --minify | grep namespace:

Ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#setting-the-namespace-preference

Upvotes: 14

Related Questions