Skip to main content

More Info:

Kubernetes provides a default namespace, where objects are placed if no namespace is specified for them. Placing objects in this namespace makes application of RBAC and other controls more difficult.

Risk Level

Low

Address

Security

Compliance Standards

  • CIS Kubernetes

Triage and Remediation

Remediation

Manual Steps

  1. List objects currently in the default namespace
    • Run on: any machine with kubectl access
    Review whether any of these are application workloads or app-specific config, versus core/cluster-level components intentionally left in default.
  2. Identify owners and usage of each non-system object in default
    • Run on: any machine with kubectl access
    For each object, determine which team/application it belongs to and whether it should be isolated (e.g., by team, environment, or function).
  3. Design or confirm appropriate target namespaces
    • Decide, per application or team, which dedicated namespace should be used (for example: team-a-prod, payments, monitoring).
    • If a needed namespace does not exist, create it:
    • Ensure any required RBAC, NetworkPolicies, and quotas are or will be defined in that namespace.
  4. Plan and execute migration of workloads from default to target namespaces
    • Export existing manifests from default and rewrite them to use the new namespace:
    • Edit /tmp/default-ns-resources.yaml:
      • Remove status fields and autogenerated metadata (resourceVersion, uid, creationTimestamp, etc.).
      • Change metadata.namespace: default (or add namespace:) to the chosen <target-namespace> for each object.
    • Apply into the new namespace:
    • After verifying the new objects run correctly, delete the originals from default:
  5. Harden processes so new resources aren’t created in default
    • For cluster-wide defaults (contexts):
    • Review CI/CD pipelines, Helm charts, and operators to ensure they explicitly set metadata.namespace or use a non-default namespace in their configurations and release manifests.
  6. Verify that default is no longer used for application resources
    • Run on: any machine with kubectl access
    Confirm that only intentionally-approved core objects (if any) remain in default, and document any exceptions with justification.
Interpretation / what indicates a problem:
  • From commands (1) and (2):
    • Problematic: you see application workloads (Deployments, StatefulSets, DaemonSets, Pods, Services, Ingresses, Jobs, CronJobs, ConfigMaps, Secrets, etc.) that belong to specific apps/teams running in the default namespace.
    • Acceptable: only system- or bootstrap-related objects intentionally kept there (and preferably none; many orgs aim for an empty default namespace).
  • From command (3):
    • Problematic: RoleBindings/Permissions clearly tied to an application or team defined in default instead of a dedicated namespace.
  • From command (4):
    • Problematic: application-specific ServiceAccounts (e.g. payments-api-sa, frontend-sa) in default rather than in their application namespace.
  • From command (5):
    • Problematic: the printed namespace is empty (meaning default) while you normally create app resources from this context. This suggests new resources may be landing in default unintentionally.
  • From command (6):
    • If there are no meaningful non-system namespaces for your apps (everything is effectively using default), that indicates you have not implemented namespace-based segregation as recommended.
Verification after you make changes (e.g., move workloads to dedicated namespaces and adjust your kubectl default namespace):
How to use and interpret this script
  • Run on any machine with kubectl access:
    bash report-default-namespace-usage.sh
  • Problem indication:
    • Any non-empty listings (Deployments, Pods, Services, ConfigMaps, Secrets, etc.) in the default namespace.
    • Any non-zero counts in the “Summary” section.
    • Any ClusterRoleBinding subjects that reference namespace: "default".
These outputs mean the default namespace is still being used and those resources should be reviewed and, where appropriate, migrated into purpose-built namespaces.