Introduction
In some of the cases, we need to specify namespace name along with kubectl commands.
Example of get pods command with namespace:
kubectl --namespace my-namespace get podsIts very tedius to specify these two strings every time you are running kubectl commands. Especially, when you have multiple namespaces. Its frustrating to copy-paste them each time.
How to Set Namespace With the Context
Assumming, the name of your namespace is my-namespace.
Command to set namespace with a context:
kubectl config set-context --current --namespace my-namespaceNow, if you do: kubectl config get-contexts
You will see a namespace name along with the context name, something like:
* cluster-name cluster-name xyz my-namespaceRun Commands without Specifying Namespace
Now, you can run normal kubectl commands without mentioning namespace.
kubectl config get-contexts
kubectl get pods
kubectl apply -f <path to yaml>Thanks for reading…










