What is Kubernetes Namespace?

Photo of author

By admin

While IT specialists may be using terms like Kubernetes and Kubernetes namespaces on a daily basis, it is very uncommon for a beginner to have a great hold on such technical topics and terms. It’s because these terms have no particular use in our daily lives. However, if you are associated with the IT industry and particularly focusing on working with Kubernetes, you may have come across this quite common question – what is Kubernetes namespace?

Well, namespaces are components of Kubernetes, which partition a single cluster into different virtual clusters. If you’re stepping into the world of application development, you must possess a good knowledge of Kubernetes to have certain advantages. Yes, this will also help save both your time and resources when it comes to developing top-notch applications.

However, this article not only answers “what is Kubernetes namespace” but also explains the associated terminology in simple language to help you understand Kubernetes namespaces better. So, let’s get started!

Important Definitions

Certain definitions are used frequently while talking about the Kubernetes namespace. Let’s understand them before moving forward.

  • Container: A container is nothing but a ready-to-run software package that contains everything required to run an app: starting from the code to application system libraries, default values related to essential settings, and any runtime that it requires; a container has it all.
  • Cluster: Every container runs on a cluster. It includes a control plane and computer machine nodes. A control plane takes care of the applications running on the cluster and what resources they use, while nodes are the machines on which the clusters run.
  • Orchestration: Ever seen an orchestra? The orchestra conductor decides what sound he needs, how many violins, how many trumpets, what octave, and everything else. Similarly, it’s the orchestration that decides which container shall be used, what resources will be used, which application will run, etc.
  • Kubernetes: Kubernetes comes from a Greek word that means sailing master or pilot. In simple words, it means someone who has significant control over the operations. This is what Kubernetes does. It manages clusters, their deployment, scaling, etc.

These definitions will help you understand better what is “Kubernetes Namespaces.”

What is Kubernetes Namespace?

With the help of a namespace, each cluster is divided into virtual sub-clusters. Every team can work on a namespace without disturbing others. A cluster has an application and its dependencies stored in namespaces. These namespaces are logically separate from each other but have the permission to communicate with each other. It’s the namespaces that allow the projects and team members to share a cluster.

Let’s understand this by comparing how things have changed and how these technologies are changing the way application development takes place.

Earlier, resource allocation was an issue. One application may eat up most of the resources causing other applications to underperform. Deploying numerous physical servers was not a possibility for organizations.

It’s the concept of virtualization that came into the picture and provided a viable solution to the aforesaid problem. With the help of virtualization software, it became possible to run multiple virtual machines on a single CPU. This saved organizations from additional costs for buying and maintaining extra hardware. Virtualization also has provided scalability as resources could be added or removed anytime without disturbing other VMs. It also showcased enhanced security as a VM was not accessible by other VMs.

This is the Kubernetes era where containers facilitate application development and make the whole process a lot easy. These containers are quite the same as virtual machines but they are lightweight. They have relaxed isolated properties as they can be shared across multiple operating systems, have their own CPU space, memory, etc., and are detached from their respective infrastructure.

How to Share a Cluster with Namespaces?

A namespace allows teams to share Kubernetes Cluster by giving it a name and adding authorization and policy to a sub-cluster.

But before sharing the cluster, you must have-

  1. An existing cluster.
  2. A basic understanding of the Kubernetes terminology.

There are three namespaces in Kubernetes.

  1. Default – The default namespace is for the objects with no other namespace .
  2. Kube-system – The namespace for the Kubernetes system originated objects.
  3. Kube-public – The namespace used for resources that need to be publicly available to all users.

Default Namespace

Before moving forward, you must know about the default namespace. It is a namespace that is created automatically by Kubernetes. This namespace houses the pods, services, and deployment which are accessible by every user (even the unauthenticated ones).

Viewing Namespaces

You can view your current namespaces using the following command:

kubectl get namespaces

It will list down your existing namespaces, their status, etc.

If you want to know the summary of a specific namespace, you can use the following command:

Kubectl get namespaces <name>

You can also get a detailed description of a specific namespace by using the following command:

Kubectl describe namespace <name>

The description shows the resource quota (if specified) and the resource range, where the resource quota shows the aggregate amount of resources a namespace can use, and the resource range shows the minimum or maximum resources that can be consumed.

It also shows whether a namespace is active or terminating. These are the two statuses of any namespace. An active namespace is the one in current use, while a terminating namespace is the one that is being deleted and cannot be used further.

Creating a New Namespace

You can create a new namespace in two ways:

1. You can simply run the command:

kubectl create namespace <insert-namespace-name-here>

2. You can also create a YAML file with the following contents:

Newspace.yaml:
kind: Namespace
apiVersion: v1
metadata:
name: newspace
labels:
name: newspace
kubectl apply-f newspace.yaml

It is easy to create a new namespace. Just remember to not add the prefix “kube’ before a namespace.

Deleting a Namespace

It is very easy to create as well as to delete a namespace. Delete a namespace by using the following command:

Kubectl delete namespace <insert-namespace-name-here>

After entering this command, the namespace will show a “Terminating” status for a while.

Why Should You Use Kubernetes Namespaces?

Now, you have an idea about how you can use namespaces and how you can create, view, or delete namespaces. So, it’s time to understand why Kubernetes namespaces are popular and what are their benefits:

  1. A namespace is used by a particular team, which increases the sense of accountability through enhanced role-based access control.
  2. Namespaces allow teams to work in their respective bubbles without interfering with and disturbing others.
  3. With namespaces, it is possible to undertake the development, testing, and production of applications in different containers.
  4. The resource quota divides the number of resources that can be used by users and the teams.

Using Multiple Namespaces

In smaller organizations, development, testing, and production teams work side-by-side; thus a default namespace is sufficient. The development and testing do not need isolation and, thus, can work with a single default namespace.

But in case the team is large or expanding day-by-day, multiple namespaces become a need. You can understand the use of multiple namespaces below:

  1. Development and testing may be clustered into one team, and production can be isolated so that whatever changes are made by development and testing do not affect the production. Throughout the complete lifecycle of the application, the two teams can work on their respective namespaces.
  2. The problem with the traditional development was the uneven division of resources, which virtual machines and containers have overcome. You can decide the resources or CPU memory usage limit for every project.
  3. The resources and servers can be separated using namespaces, which allow isolated working for teams.
  4. Each namespace has separate roles and a responsibility list that can be used under a single name, thus restricting only authorized users to access a namespace.

Final Thoughts

Kubernetes gives an organization the freedom to work in its own space with an allocated amount of resources. This allows organizations to utilize both their time and resources in an optimum manner without causing clutter among the teams. Kubernetes namespaces facilitate application development and make everyday tasks of developers easy to accomplish. After reading this article, you must be aware of the various benefits of using the Kubernetes namespace along with the common commands to view, create, and delete namespaces.

Leave a Comment