Creating a Kubernetes namespace.

Kubernetes Create Namespace: A Practical Tutorial

Learn how to use kubernetes create namespace with step-by-step examples, best practices, and tips for managing resources and security in your clusters.

Michael Guarino
Michael Guarino

By default, Kubernetes runs all resources in a single flat space where any pod can talk to any other. This lack of isolation introduces risk—a single compromised workload could affect the entire cluster. Namespaces provide the logical separation needed to reduce that risk and enable multi-tenant environments. They form the basis for enforcing controls like Role-Based Access Control (RBAC) and NetworkPolicies. Creating a namespace is just the first step. This tutorial walks through not only how to create namespaces but also how to apply security best practices that limit blast radius and enforce least privilege across workloads.

Unified Cloud Orchestration for Kubernetes

Manage Kubernetes at scale through a single, enterprise-ready platform.

GitOps Deployment
Secure Dashboards
Infrastructure-as-Code
Book a demo

Key takeaways:

  • Use namespaces to isolate workloads and teams: Go beyond the default namespace to create dedicated, logical environments. This prevents naming conflicts and provides a clear structure for organizing resources by project, team, or deployment stage like dev, staging, and prod.
  • Apply policies to enforce security and resource limits: A namespace only provides logical separation. To create true boundaries, you must apply ResourceQuotas to prevent resource contention, NetworkPolicies to control traffic, and RBAC rules to enforce least-privilege access for users and applications.
  • Manage namespace configurations declaratively for scalability: Avoid manual kubectl commands for production environments. Instead, define all namespace configurations—including quotas, policies, and RBAC—as code in a Git repository to ensure consistency, enable automation, and simplify management across a growing fleet of clusters.

What Is a Kubernetes Namespace?

A Kubernetes namespace is a way to partition a single cluster into multiple isolated environments. It provides logical boundaries so that different teams, projects, or environments can share the same cluster without interfering with each other. Namespaces group related resources—Pods, Services, Deployments—under a common scope, preventing naming conflicts. For example, you can run an api-gateway service in both dev and prod namespaces without collisions.

Namespaces also define the scope for policies. You can apply access controls, quotas, and network restrictions at the namespace level to enforce security and resource management. As environments scale across teams and clusters, consistent namespace management becomes essential for keeping workloads organized and secure.

How Namespace Isolation Works

Namespaces provide logical isolation, not physical. All workloads still run on the same underlying nodes, so resource contention is possible if limits aren’t enforced. Kubernetes offers tools to strengthen namespace boundaries:

  • ResourceQuotas: set caps on CPU, memory, and storage usage within a namespace to prevent one team’s workload from starving others.
  • NetworkPolicies: restrict pod-to-pod communication, effectively acting as firewalls at the namespace level.

Together, these controls prevent noisy neighbors and limit cross-namespace exposure.

Default Namespaces in a Cluster

When a Kubernetes cluster is created, it comes with a few built-in namespaces:

  • default: the fallback namespace for resources created without an explicit namespace. Avoid using it for production workloads.
  • kube-system: reserved for core system components like the API server, scheduler, and controller manager. Do not modify resources here.
  • kube-public: readable by all users, including unauthenticated ones. Typically used for cluster-wide info.
  • kube-node-lease: stores Lease objects that track node heartbeats and availability.

Why Use Namespaces?

Namespaces bring order to Kubernetes clusters by grouping resources logically—for example, by environment (dev, staging, prod), by team, or by application. They prevent naming conflicts and make clusters easier to navigate and debug.

More importantly, namespaces are the foundation for security and governance. With them, you can:

  • Apply RBAC rules so teams only have access to their workloads.
  • Enforce ResourceQuotas for fair resource distribution.
  • Scope NetworkPolicies to control communication paths.

Using namespaces is a baseline best practice for any serious Kubernetes deployment, enabling both organization and security at scale.

How to Create a Namespace

Namespaces can be created either imperatively with kubectl commands or declaratively using YAML manifests. Imperative creation is fast and useful for ad hoc tasks, while declarative creation is the standard for production since it aligns with Infrastructure as Code (IaC) practices and makes configurations reproducible.

Create a Namespace with kubectl

The quickest way is with a kubectl command:

kubectl create namespace <name>

This immediately creates the namespace and is fine for development, testing, or temporary setups. However, it’s not ideal for production since it isn’t tracked in version control, making it harder to audit or replicate.

Create a Namespace with a YAML Manifest

For production environments, use a declarative YAML manifest:

apiVersion: v1
kind: Namespace
metadata:
  name: my-namespace

Save this to a file (e.g., namespace.yaml) and apply it with:

kubectl apply -f namespace.yaml

This approach ensures the configuration is versioned, auditable, and portable across clusters—critical for GitOps workflows.

Validate Your Namespace

After creation, confirm that the namespace exists:

kubectl get namespaces

For more detail, including labels and annotations:

kubectl describe namespace <name>

In large environments, repeatedly validating via CLI can get tedious. Tools like Plural offer dashboards to visualize and manage namespaces across clusters without juggling multiple kubeconfigs.

Avoid Common Mistakes

  • Overusing the default namespace: Putting everything in default complicates permissions and resource management. Instead, create dedicated namespaces for environments (dev, staging, prod) or teams.
  • Ignoring resource quotas: Without quotas, a single workload can monopolize cluster resources, causing instability. Always define quotas when creating namespaces to enforce fair usage and prevent noisy-neighbor issues.

How to Manage Resources in a Namespace

Creating a namespace is only the first step—what really matters is how you control and organize resources within it. Without proper management, namespaces can quickly become cluttered, leading to resource contention, security gaps, and operational slowdowns. Effective namespace management means setting consumption limits, controlling network traffic, and applying consistent organizational standards as your cluster scales.

Doing this manually across a handful of namespaces is manageable, but at fleet scale it becomes overwhelming. Repeatedly applying YAML or kubectl commands to dozens of clusters is error-prone and nearly impossible to audit. That’s why many teams turn to unified platforms and GitOps workflows. For example, tools like Plural let you define quotas, policies, and RBAC rules once and roll them out consistently across clusters—keeping everything secure, auditable, and automated.

1. Set Resource Quotas and Limits

The first step to stable multi-tenant clusters is enforcing resource boundaries:

  • ResourceQuota objects define the total amount of CPU, memory, and other resources a namespace can consume. They can also cap the number of objects (Pods, Services, PVCs, etc.) created.
  • LimitRange objects set default CPU/memory requests and limits for containers, ensuring no pod runs unbounded.

Together, they prevent a single workload from starving out others—critical in shared clusters.

2. Define Network Policies

By default, all pods in Kubernetes can talk to each other, across namespaces. This “open by default” model is convenient but risky.

  • NetworkPolicy objects let you explicitly define which pods can communicate, both ingress and egress.
  • Using label selectors, you can lock down traffic within a namespace or permit specific cross-namespace flows.

This transforms namespaces from loosely separated environments into secure, isolated workspaces, enforcing least-privilege networking.

3. Manage Cross-Namespace Communication

Isolation doesn’t mean total disconnection—apps often need to talk across namespaces. Kubernetes makes this possible through DNS:

<service-name>.<namespace>.svc.cluster.local

For example, a pod in namespace-a can reach my-service in namespace-b at:

my-service.namespace-b.svc.cluster.local

But remember:

  • You need a NetworkPolicy that explicitly allows the traffic.
  • Some resources (e.g., Secrets, ConfigMaps) are strictly namespace-scoped and can’t be shared directly.

Plan application design with these constraints in mind.

4. Apply Consistent Naming and Labels

Namespaces multiply quickly, and without naming conventions, chaos follows. Best practice is to use a simple, descriptive pattern like:

team-project-environment

Example: billing-api-production.

Beyond names, labels are the real organizational power tool:

  • Add consistent labels like team: billing, env: prod, or cost-center: 12345.
  • Use them to query, select, and apply policies to groups of resources.

Labels form the foundation for scalable RBAC, quotas, and network policies.

How to Secure Your Namespaces

Namespaces give you logical separation, but not security by default. To achieve real isolation, you need to layer multiple controls that enforce least privilege across access, runtime behavior, and networking. A secure namespace strategy covers who can access resources, how workloads run, and how pods communicate.

Secure Access with RBAC

RBAC is the backbone of Kubernetes security. Within a namespace:

  • Roles define permissions like get, list, or delete pods.
  • RoleBindings grant those permissions to users, groups, or service accounts.

This ensures a developer working in dev can’t accidentally impact prod.

Managing access manually across multiple clusters can get messy. Plural integrates with your identity provider, so you can apply Kubernetes RBAC policies using the same user and group identities you already have. With impersonation and SSO built in, Plural provides a consistent, fine-grained access model across your entire fleet—without the hassle of juggling kubeconfigs.

Use Service Accounts for Granular Permissions

RBAC controls user access; Service Accounts control pod-level access. Every namespace comes with a default service account, but relying on it means all workloads share the same permissions. Instead:

  • Create dedicated service accounts for each app.
  • Assign only the minimal permissions required.

For example:

  • A CI/CD job might need rights to create Deployments.
  • A monitoring agent only needs read access to pod metrics.

This approach follows least privilege and limits the blast radius if an application is compromised.

Configure Security Contexts

Security contexts define runtime rules for pods and containers. They’re a critical safeguard against container breakout and privilege escalation. Useful settings include:

  • runAsUser: enforce non-root execution.
  • readOnlyRootFilesystem: true: prevent writes to the root filesystem.
  • allowPrivilegeEscalation: false: block privilege escalation.
  • Drop unused Linux capabilities.

Enforcing strict security contexts ensures that even if an attacker compromises a container, their ability to escalate is severely limited.

Isolate Workloads with Network Policies

By default, Kubernetes networking is wide open—every pod can talk to every other pod. This is fine for testing but risky in production.

  • NetworkPolicy objects act as a firewall at the namespace level.
  • Best practice is to start with a default-deny policy and explicitly allow required traffic.

For example:

  • Allow ingress traffic to frontend pods only from the ingress controller.
  • Permit frontend pods to communicate with backend pods—but block all other traffic.

Platforms like Plural make it easy to apply these policies consistently across your clusters. Instead of manually applying YAMLs, you can enforce them fleet-wide through a GitOps workflow with a single source of truth.

How to Monitor and Maintain Namespaces

Creating namespaces is just the first step. To keep your cluster organized, secure, and efficient, you need a solid strategy for ongoing monitoring and maintenance. Without it, namespaces can become cluttered with abandoned resources, suffer from performance bottlenecks, or introduce security vulnerabilities. Effective maintenance involves tracking resource usage, troubleshooting issues as they arise, and establishing clear lifecycle management policies. This proactive approach ensures your cluster remains stable and scalable, allowing your teams to operate without friction.

Tools for Monitoring Namespace Health

Effective Kubernetes monitoring is essential for understanding the health of your namespaces. It allows you to track resource utilization—like CPU, memory, and storage—and identify performance issues before they cause outages. Open-source tools like Prometheus and Grafana are standard for collecting metrics and creating dashboards that visualize namespace-level data. These tools help you see which namespaces are consuming the most resources or if a specific application is experiencing performance degradation. By setting up alerts, you can be notified proactively when a namespace exceeds its resource quotas or when pods within it start failing, enabling you to address problems quickly.

Troubleshoot Common Namespace Issues

When things go wrong, knowing where to look is critical. Common namespace issues often stem from resource constraints, network policy misconfigurations, or RBAC permission errors. If pods are stuck in a Pending state, it could mean the namespace has hit its resource quota. Use kubectl describe namespace <namespace-name> to check quotas and limits. For connectivity problems, review the NetworkPolicies applied to the namespace to ensure they aren't blocking necessary traffic. Permission-denied errors often point to missing RoleBindings. A systematic approach to checking events, logs, and resource configurations will help you pinpoint the root cause of most namespace-related problems.

Develop a Namespace Cleanup Strategy

Over time, clusters can accumulate unused namespaces, especially in development environments where they are created for temporary testing or feature branches. This "namespace sprawl" consumes resources and adds clutter, making the cluster harder to manage. To prevent this, establish a clear cleanup strategy. You can implement automation to detect and delete inactive namespaces after a certain period. Another effective method is to use labels to mark namespaces with an owner or expiration date, making it easy to identify which ones can be safely removed. Adopting hierarchical namespaces can also help by allowing you to manage related namespaces as a group.

Automate Namespace Management with Plural

Manually monitoring and maintaining namespaces across a large fleet of clusters doesn't scale. Plural provides a single pane of glass to observe and manage all your Kubernetes environments. The embedded Kubernetes dashboard gives you full visibility into every namespace without juggling kubeconfigs or dealing with complex network configurations. You can use Plural CD to automate the deployment of monitoring tools, resource quotas, and network policies, ensuring consistency across your entire fleet. This centralized approach simplifies troubleshooting and reduces the operational burden of maintaining a clean and secure multi-cluster environment.

Integrate Namespaces into Your GitOps Workflow

The best way to maintain consistency and control over your namespaces is to manage their configurations declaratively through a GitOps workflow. By defining namespaces, ResourceQuotas, NetworkPolicies, and RBAC rules in YAML manifests stored in a Git repository, you create a single source of truth. Plural’s GitOps-based continuous deployment automatically syncs these configurations to your target clusters, ensuring that any changes are version-controlled, reviewed, and applied consistently. This approach eliminates configuration drift and makes it simple to roll back changes if issues arise. Integrating namespace management into your GitOps pipeline turns a complex maintenance task into a streamlined, auditable process.

Unified Cloud Orchestration for Kubernetes

Manage Kubernetes at scale through a single, enterprise-ready platform.

GitOps Deployment
Secure Dashboards
Infrastructure-as-Code
Book a demo

Frequently Asked Questions

When should I use a new namespace versus a whole new cluster? You should use a new namespace when you need to logically separate teams, projects, or environments (like dev vs. prod) that can safely share the same underlying cluster resources. Namespaces are perfect for organizational clarity and applying specific access or resource policies. A whole new cluster is necessary when you require complete physical isolation, for instance, to meet strict compliance requirements, guarantee resource availability for a critical application, or manage workloads with vastly different hardware needs.

What's the biggest mistake people make with the default namespace? The most common mistake is using the default namespace as a dumping ground for production applications. While it's convenient for quick tests, relying on it for real workloads leads to a disorganized cluster where it's difficult to manage permissions, track resource usage, or prevent naming conflicts. This makes the environment harder to secure and scale. A much better practice is to create dedicated namespaces for each application or team from the start.

How do I give a team access to only their specific namespace? You can restrict a team's access by using Kubernetes Role-Based Access Control (RBAC). The process involves creating a Role object within the team's namespace that defines what actions they can perform (e.g., view pods, edit deployments). Then, you create a RoleBinding to connect that Role to the team's user group. This ensures they can only operate within their designated boundaries and can't see or modify resources in other namespaces.

Can pods in different namespaces talk to each other? By default, yes. Kubernetes allows open communication between all pods in a cluster, regardless of their namespace. However, this is often not desirable from a security perspective. You can control this traffic by implementing NetworkPolicy objects. These act as a firewall, allowing you to create explicit rules that define which pods are allowed to communicate, effectively locking down communication unless it's explicitly permitted.

How can I apply the same security rules and resource limits to namespaces across many different clusters? Managing configurations like RBAC policies and ResourceQuotas consistently across a fleet of clusters is a significant challenge with manual methods. This is where a platform like Plural becomes essential. By using Plural's GitOps-based continuous deployment, you can define your namespace configurations as code in a central repository. Plural then automatically syncs these policies to all your target clusters, ensuring every namespace adheres to your standards without manual intervention.

Guides