More Info:
Using the default namespace for user workloads makes it harder to apply access controls and network policies. Place workloads in dedicated namespaces instead.Risk Level
LowAddress
SecurityCompliance Standards
- CIS AKS
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
List all user resources in the default namespace
- Run on: any machine with kubectl access
-
Create one or more dedicated namespaces for your workloads (per app/team as needed)
- Run on: any machine with kubectl access
-
Migrate workload controllers (Deployment/StatefulSet/DaemonSet/Job/CronJob) out of default
- Run on: any machine with kubectl access
- For each controller in
default, choose a target namespace and run:
- Use the same pattern for
statefulset,daemonset,job, andcronjobresources.
-
Migrate Services, Ingresses, and supporting objects (ConfigMaps, Secrets, ServiceAccounts, Roles, RoleBindings, NetworkPolicies)
- Run on: any machine with kubectl access
- For each resource in
default, re-apply into the target namespace and then delete fromdefault. Examples:
- Repeat for other names/resources until
kubectl get all -n defaultonly shows thekubernetesService.
-
Update clients/manifests to stop using the default namespace
- Run on: any machine with kubectl access
- Ensure your manifests declare the correct namespace:
- If you use a kubeconfig context, set a non-default namespace:
-
Verification (default namespace has no user workloads)
- Run on: any machine with kubectl access
Using kubectl
Using kubectl
On any machine with kubectl access:
-
Create replacement namespaces for workloads currently in
default
Example (adjust names as needed):Or via manifest: -
List all user resources in the
defaultnamespace (to plan migration): -
For each user workload in
default, reapply it into a non-default namespace, then delete the original.
Example for a deployment:Example for a service:Example for a configmap: -
For resources that may not have an explicit
namespace:field (e.g., some autogenerated manifests), you can set it during reapply: -
Repeat step 3 for all user-defined objects in
default(deployments, statefulsets, daemonsets, jobs, cronjobs, services, ingresses, configmaps, secrets, PVCs, etc.), making sure interdependent resources are moved into the same new namespace. -
Verification (CIS-aligned):
Automation
Automation

