liveBook · Manning

Kubernetes namespace

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A Kubernetes namespace is a logical partition that scopes and organizes namespaced resources within a cluster.

A Kubernetes namespace groups resources within a cluster. Think of it as a dedicated virtual environment for those resources, not a separate cluster. The default namespace is available for deploying applications; the controller manager creates default accounts and API access tokens for new namespaces. section 1.5

Use `kubectl get ns` to list namespaces (`ns` is the shorthand). System components, including the API server, scheduler, CoreDNS, and etcd, have pods in `kube-system`. Do not confuse a Kubernetes namespace with the Linux namespaces used to isolate containers in a kind cluster. section 2.1.4 section 9.3.1

Create resources in a namespace

Run `kubectl create ns c01383`, then `kubectl -n c01383 create deploy nginx --image nginx` and `kubectl -n c01383 expose deploy nginx --name nginx-svc --port 80`. Verify the result with `kubectl -n c01383 get deploy,svc`. The `-n` flag selects the namespace for each resource command. section 6.2.4

Namespace scope also matters when resolving Service names. From a pod in `c01383`, `curl apache-svc` cannot resolve a Service in `default`, but `curl apache-svc.default` succeeds. Use the namespace-qualified name when checking cross-namespace Service access; the Service naming pattern is `<service-name>.<namespace-name>.svc.cluster.local`. section 6.2.4

root@nginx-76d6c9b8c-8lqgg:/# cat /etc/resolv.conf
search c01383.svc.cluster.local svc.cluster.local cluster.local
nameserver 100.96.0.10
options ndots:5

The pod’s `/etc/resolv.conf` lists `c01383.svc.cluster.local` in its DNS search path, helping explain why an unqualified Service name is looked up in the pod’s namespace. section 6.2.4

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through creation, resource verification, and a cross-namespace DNS test, without detailing namespace internals.
Examples
Uses a new namespace containing an nginx Deployment and Service, plus successful and failed curl lookups across namespaces.
What it assumes
Assumes a working Kubernetes cluster and familiarity with pods, Deployments, Services, and kubectl; demonstrates namespace creation directly.
What you can do after
Operate/configure it with kubectl to create a namespace, inspect its resources, and check cross-namespace Service names.
How it connects
Links namespaces to Deployments, Services, pods, Service DNS, and control-plane components.

Also explained in

Compare how 5 books explain Kubernetes namespace →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.