Skip to main content

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

Low

Address

Security

Compliance Standards

  • CIS AKS

Triage and Remediation

Remediation

Manual Steps

  1. List all user resources in the default namespace
    • Run on: any machine with kubectl access
  2. Create one or more dedicated namespaces for your workloads (per app/team as needed)
    • Run on: any machine with kubectl access
  3. 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, and cronjob resources.
  4. 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 from default. Examples:
    • Repeat for other names/resources until kubectl get all -n default only shows the kubernetes Service.
  5. 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:
  6. Verification (default namespace has no user workloads)
    • Run on: any machine with kubectl access
On any machine with kubectl access:
  1. Create replacement namespaces for workloads currently in default
    Example (adjust names as needed):
    Or via manifest:
  2. List all user resources in the default namespace (to plan migration):
  3. 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:
  4. For resources that may not have an explicit namespace: field (e.g., some autogenerated manifests), you can set it during reapply:
  5. 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.
  6. Verification (CIS-aligned):