Namespaces and resource scope
Two teams, one cluster
A namespace gives namespaced Kubernetes resources a naming and organizational scope. Imagine a bookshop team testing a catalog while another team runs a staging copy. Both can have a Pod named catalog-a because they live in distinct namespaces. A Node, in contrast, is a cluster-scoped object rather than a member of either namespace. All examples are offline illustrations, not observed cluster output. Optional read-only commands require an explicitly approved disposable cluster, a separately prepared ./lab.kubeconfig, a verified bytemind-lab context and matching fixture inventory. No cluster or kubeconfig is included. Do not query an unknown context.
KIND NAMESPACE NAMENamespace — book-labNamespace — stage-labPod book-lab catalog-aPod stage-lab catalog-aNode — lab-node-1The two Pod records have different identities. The dash is a display convention for a resource with no namespace, not a namespace name. The actual inventory is in inventory.json.
Recognize namespaced and cluster-scoped kinds
A namespace is not a nested folder structure. Namespaces cannot contain other namespaces. Namespaced objects include Pods, Services, Deployments and ConfigMaps. Nodes, Namespaces, PersistentVolumes and ClusterRoles have cluster scope. A name is unique within its resource type and scope, so a ConfigMap and a Pod may share a name in the same namespace. The API server assigns a UID to each object lifetime; deleting and recreating an object with the same name does not preserve that identity.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab api-resources --namespaced=truekubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab api-resources --namespaced=falseThe first list contains served namespaced resources; the second contains served cluster-scoped ones. Extensions can add resource kinds. These commands contact the API; use the offline inventory if no approved cluster exists.
Declare a namespace
A Namespace is a core API object. Use a valid DNS label for its name. The following file is a static candidate for a dedicated training environment. Do not add a namespace field to the Namespace object itself. Avoid names starting with kube-; system namespaces are reserved.
The manifest describes an intended Namespace; merely saving it changes nothing. A permitted API request would be required to create it. This chapter does not instruct you to create or remove namespaces.
Select the namespace explicitly
The namespace flag limits a namespaced request. If omitted, kubectl uses the context namespace preference, or default when no preference is set. The context also identifies a cluster and user. A namespace flag does not change the selected cluster or grant any permissions.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get pod/catalog-akubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n stage-lab get pod/catalog-aThe requests refer to distinct objects. An authorized all-namespace list uses -A for namespaced kinds, but it is intentionally omitted from the lab workflow. Avoid broad reads when a single namespace is enough.
Namespaces organize; policy protects
Namespacing alone does not prevent traffic between Pods in different namespaces. Authentication and authorization control API access; a compatible network implementation and appropriate network policies control traffic. ResourceQuota and LimitRange can help govern consumption, but they must be configured. The four customary starting namespaces are default, kube-system, kube-public and kube-node-lease. System components and node heartbeats have dedicated uses; none is a practice cleanup target. Deleting a namespace can initiate removal of its namespaced objects and may remain in Terminating while cleanup is pending. Never delete a namespace to remove a single Pod.
Practice: classify the inventory
Read lab-fixtures/namespace-ownership/inventory.json. Group entries by namespace scope, explain why the duplicate Pod name is valid, and identify which commands would select only the book-lab Pod. Next, learn how labels select subsets within that scope.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Namespaces and resource scope — knowledge check
Apply the lesson concepts to original offline scenarios.
Two Pods named catalog-a exist in book-lab and stage-lab. Why is this allowed?
Which resource is cluster-scoped?
What does -n book-lab change on a get pods request?
Does placing two Pods in different namespaces automatically block their network traffic?
What is a risk of deleting an entire namespace?