Profile Applicability:

  • Level 1

Description:
 Kubernetes automatically creates a 
default namespace for all resources that are not explicitly assigned to a namespace. This check ensures that the default namespace is not used for application workloads and that custom namespaces are created for better resource organization, security, and management.

Rationale:
 Using the 
default namespace for all workloads makes it harder to manage and apply access control policies, as all resources are grouped together. By creating and using custom namespaces, you can more effectively manage workloads, apply role-based access control (RBAC) policies, and apply resource quotas. Additionally, namespaces help to isolate resources and improve security.

Impact:

  • Pros:

    • Enhances organization by categorizing workloads into custom namespaces.

    • Improves security and resource isolation by applying RBAC and resource quotas on a per-namespace basis.

    • Simplifies workload management and troubleshooting by logically grouping resources.

  • Cons:

    • Requires additional configuration and planning to ensure workloads are placed in appropriate namespaces.

    • Increases complexity for managing multiple namespaces in large environments.

Default Value:
 By default, all resources in Kubernetes are created in the 
default namespace unless another namespace is explicitly specified.

Pre-requisites:
 Ensure that namespaces are configured for different workloads, and that RBAC policies and resource quotas are in place to manage workloads effectively.

Test Plan:

Using Azure Console:

  1. Navigate to the Azure portal and review the Kubernetes resources in your Azure Kubernetes Service (AKS) cluster.

  2. Check if any workloads (pods, deployments, services) are using the default namespace.

  3. Ensure that workloads are grouped into logical custom namespaces based on team, project, or environment.

Using Azure CLI:

  1. List all resources and check their namespaces:

     kubectl get all --all-namespaces
    Generic


  2. Verify that no resources are using the default namespace for application workloads.

  3. Check if custom namespaces are used by listing namespaces:

     kubectl get namespaces
    Generic


  4. Ensure that workloads are deployed in appropriate namespaces and not in default.

Implementation Plan:

Using Azure Console:

  1. In the Azure portal, create custom namespaces for different teams, projects, or environments by navigating to Kubernetes Services and selecting Namespaces.

  2. Assign appropriate namespaces to workloads by editing the deployment specifications and ensuring they are created in their respective custom namespaces.

  3. Configure RBAC and resource quotas for each namespace to control access and manage resources effectively.

Using Azure CLI:

  1. Create custom namespaces for different workloads or teams:

     kubectl create namespace <namespace-name>
    Generic


Update deployment specifications to assign workloads to custom namespaces:

 

kubectl apply -f deployment.yaml --namespace=<namespace-name>
Generic
  1. Assign RBAC roles to users based on the namespace using the following command:

     kubectl create rolebinding <rolebinding-name> --role=<role-name> --serviceaccount=<namespace-name>:<service-account-name> --namespace=<namespace-name>
    Generic


  2. Ensure that all application workloads are deployed in their respective namespaces and not in the default namespace.

Backout Plan:

Using Azure Console:

  1. If workloads in custom namespaces cause issues, revert the configuration by switching back to the default namespace in the Azure portal.

  2. Reassign workloads to the default namespace if necessary.

Using Azure CLI:

  1. Revert any namespace-related changes by moving resources back to the default namespace:

     kubectl apply -f deployment.yaml --namespace=default
    Generic


  2. Remove any namespace-specific RBAC or resource quota configurations if necessary.

References:

  1. Kubernetes Namespace Documentation

  2. Azure Kubernetes Service (AKS) Best Practices

  3. Kubernetes RBAC Documentation