Namespaces and Environments

Introduction: The Multi-Environment Challenge

Imagine you're working on a team that builds web applications. Your team develops new features, tests them, and eventually releases them to customers. Now, picture this scenario: a developer accidentally deploys an untested version of the application to production, causing an outage for thousands of users. This happens more often than you'd think, and it's exactly the kind of problem that Kubernetes namespaces help prevent.

Organizations typically run multiple versions of their applications simultaneously — one for developers to experiment with (dev), one for testing (staging), and one that serves real customers (prod). Without a way to logically separate these environments, it's easy to mix them up. In this lesson, you'll learn how to use Kubernetes namespaces to create isolated environments within a single cluster, providing organizational clarity and a foundation for access control policies.

Understanding Kubernetes Namespaces

A namespace in Kubernetes is like a virtual cluster within your physical cluster. It provides a way to divide cluster resources among multiple users, teams, or environments. Think of namespaces as separate folders on your computer — files in one folder don't interfere with files in another folder, even if they have the same name. Similarly, you can have a deployment called web-app in your dev namespace and another deployment also called web-app in your prod namespace, and they won't conflict with each other.

When you first set up a Kubernetes cluster, several namespaces already exist by default. The default namespace is where resources go if you don't specify a namespace. The kube-system namespace contains resources created by Kubernetes itself, like CoreDNS (the DNS service), kube-proxy, and other core components. If you've installed optional tools like the Kubernetes Dashboard, they typically also run in this namespace. The kube-public namespace is readable by all users and is typically used for resources that should be publicly accessible across the cluster. The kube-node-lease namespace holds lease objects associated with each node, which help the control plane detect node failures. You generally won't interact with these system namespaces directly — instead, you'll create your own namespaces to organize your applications.

Namespaces provide logical isolation, which means they separate resources organizationally but not physically. Pods in different namespaces can still communicate with each other if you configure networking properly. The key benefit is organizational clarity and access control — you can set different permissions for different namespaces, ensuring that developers working in the dev namespace can't accidentally modify resources in production.

Note: Namespaces alone don't enforce security boundaries. By default, users with cluster access can work with any namespace. Production environments typically combine namespaces with Role-Based Access Control (RBAC) and policy enforcement tools to restrict access, and often use separate clusters for critical environment isolation.

On CodeSignal, you'll have a fresh Kubernetes cluster where you can experiment with creating and using namespaces without worrying about breaking anything.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal