• Abhishek Shukla

Kubernetes : Namespace !

Hello Readers, I have been talking about the basics of Kubernetes, what is it and how this works with its installation and other relevant stuff. This article, I will walk you through the high level view of Namespaces.

Before I dive into Namespaces, I would want you to understand about the "Objects" of Kubernetes. The objects are nothing but the persistent entities in K8s system which are used to represent the state of your cluster . Once you create object, K8s system contantly works to ensure that object exists and will be telling about the cluster's desired state. K8s APIs are required to create, delete or modify the objects. Namespaces are one of them.

K8s supports many virtual clusters backed by same physical cluster and these virtual clusters are called namespaces. Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces. Namespaces cannot be nested inside one another and each Kubernetes resource can only be in one namespace.

Namespaces are a way to divide cluster resources between multiple users (via resource quota) e.g there are different sectors in an organisation i.e. Finance, IT and HR and each sector has different quota demands.

Now, Let's see how we can play with Namespaces.

> Viewing Namespace

> Creating Namespace

> Deleting Namespace

Viewing Namespaces

The basic "GET" command to list down the current namespaces

Notice that I haven't created any namespace yet but still you can see 4 namespaces already which are active and shows the age of being active as well. Now let me explain what are they.

These are K8s initial namespaces with which K8s starts

1. default: The default namespace for objects with no other namespace

2. kube-node-lease: This is for the objects associated with each node which improves the performance of the node heartbeats as the cluster scales.

3. kube-public: This namespace is created automatically and is readable by all users . This is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement.

4. kube-system: The namespace for objects created by the Kubernetes system

Apart from default namespaces, you can create your own as well.

Creating Namespaces

As you know , everything is on YAML for K8s , so to create namespace, you have to create a YAML file. I will be creating two namespaces ; Development and Production

# kubectl create -f dev-definition.yaml

# kubectl create -f prod-definition.yaml


API syntax :

{ "apiVersion": "v1", "kind": "Namespace", "metadata": { "name": "development", "labels": { "name": "development" } } }

once done, verify with "GET" command

Point to remember here is that a k8s namespace provides the scope for pods, services and deployments within the cluster.

So , I created a deployment with 2 replicas that is running the pod called 'abhishek1' in the 'develoment' namespace

Deleting Namespaces

Delete a namespace with 'delete' command

Note : This command deletes "everything" under the namespace. This delete is asynchronous, so for a time you will see the namespace in the Terminating state

Well, I hope this was knowledgable information for you.

Thanks and happy reading !


Recent Posts

See All

"An investment in knowledge
always pays the best interest"
Benjamin Franklin