Kubernetes Namespace

by Anish

Posted on Wednesday February 6, 2019



A Kubernetes namespace provides a mechanism to scope resources in a cluster.

Namespaces provide a unique scope for:

  • Named resources to avoid basic naming collisions.

  • Delegated management authority to trusted users.

  • The ability to limit community resource consumption.

Most objects in the system are scoped by namespace, but some are excepted and have no namespace, including nodes and users.

Viewing namespace

The following command can be used to get a list of all namespaces:

[email protected]:# kubectl get namespaces
default Active  13d
kube-public Active  13d
kube-system Active  13d

Kubernetes starts with three initial namespaces:

  • default The default namespace for objects with no other namespace
  • kube-system The namespace for objects created by the Kubernetes system
  • kube-public This namespace is created automatically and is readable by all users (including those not authenticated).

View the pods running on kube-system namespace

[email protected]:# kubectl get pods -n kube-system
NAME                                  READY     STATUS    RESTARTS   AGE
coredns-78fcdf6894-rbfq8              1/1       Running   0          13d
coredns-78fcdf6894-ttbqz              1/1       Running   0          13d
etcd-kube-master                      1/1       Running   0          13d
kube-apiserver-kube-master            1/1       Running   0          13d
kube-controller-manager-kube-master   1/1       Running   0          13d
kube-flannel-ds-hzz8t                 1/1       Running   0          13d
kube-flannel-ds-vsr2h                 1/1       Running   0          13d
kube-proxy-5vmws                      1/1       Running   0          13d
kube-proxy-7zm5v                      1/1       Running   0          13d
kube-scheduler-kube-master            1/1       Running   0          13d
tiller-deploy-85744d9bfb-qj9p4        1/1       Running   0          13d

Creating Namespace

A namespace allows a community of users to organize and manage their content in isolation from other communities. Users must be given access to projects by administrators, or if allowed to create projects, automatically have access to their own projects.

The YAML definition of creating the namespace with


    "kind": "Namespace",
    "apiVersion": "v1",
    "metadata": {
        "name": "prod",
        "labels": {
            "name": "prod"

The following command will create for namespace which will be used for devops purpose namely DEV,PROD,QA,STAG under which the resources would be managed accordingly.

[email protected]:# kubectl create -f https://raw.githubusercontent.com/anishnath/kubernetes/master/devops-namespace.yaml
namespace/dev created
namespace/prod created
namespace/qa created
namespace/stag created

Viewing namespace with labels

[email protected]:# kubectl get namespaces --show-labels
NAME          STATUS    AGE       LABELS
default       Active    13d       <none>
dev           Active    58s       name=dev
kube-public   Active    13d       <none>
kube-system   Active    13d       <none>
prod          Active    58s       name=prod
qa            Active    58s       name=qa
stag          Active    58s       name=stag
  • A Kubernetes namespace provides the scope for Pods, Services, and Deployments in the cluster.
  • Users interacting with one namespace do not see the content in another namespace.

Launch a busy box pods in qa namespace

[email protected]:# kubectl create -f https://raw.githubusercontent.com/anishnath/kubernetes/master/busybox.yaml -n qa
pod/busybox created
[email protected]:# kubectl get pods -n qa 
busybox   1/1       Running   0          12s

Launch a busy box pods in dev namespace

[email protected]:# kubectl create -f https://raw.githubusercontent.com/anishnath/kubernetes/master/busybox.yaml -n dev
pod/busybox created
[email protected]:# kubectl get pods -n dev
busybox   1/1       Running   0          8s

Deleting the Namespace

[email protected]:# kubectl delete namespace dev
namespace "dev" deleted

Warning: When a namespace is deleted, it will delete all the associated k8 resource along with.

Thanku for reading !!! Give a Share for Support

Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9

python Cryptography Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers