Configuring Default Namespace for Efficient EKS Cluster Management

Ramesh Babu Chayapathi
2 min readSep 5, 2024

--

To set a default custom namespace in an Amazon EKS (Elastic Kubernetes Service) cluster, you can configure the kubectl context to use the desired namespace by default. This prevents you from having to specify the --namespace flag in every command. Here’s how you can set the default namespace:

Step-by-Step Process to Set Default Namespace

  1. Identify Your Current Context: First, determine which Kubernetes context you are currently using. The context includes the cluster, user, and namespace information.
kubectl config current-context

2. Set the Default Namespace for Your Context: Update the kubectl configuration to use your desired namespace as the default for the current context. Replace <your-context> with your current context name and <your-namespace> with the namespace you want to set as default.

kubectl config set-context <your-context> --namespace=<your-namespace>

For example, if your context is eks-prod and you want to set the default namespace to custom-namespace, you would run:

kubectl config set-context eks-prod --namespace=custom-namespace

3. Verify the Default Namespace Setting: To ensure the default namespace has been set correctly, you can check the context configuration:

kubectl config view --minify | grep namespace:

This command will show the namespace currently set as default for your active context.

Additional Notes

  • Changing Contexts: If you switch contexts, you may need to set the default namespace for each context separately.
  • Reverting to Default Namespace: To revert to the default default namespace, you can set the namespace back to default:
kubectl config set-context <your-context> --namespace=default

By setting a default namespace, you simplify your workflow, especially when working within a specific namespace frequently in your EKS cluster.

--

--

No responses yet