Kubernetes Namespaces

Kubernetes Namespaces

Table of contents

No heading

No headings in the article.

Kubernetes uses namespaces to make the environment isolated.

In this blog, let us understand what that means through visuals and a hands-on demo.

To get the namespaces,

kubectl get ns

There are 4 types of namespaces.

  1. Default: It is the initial namespace where objects are created if you don't explicitly specify a namespace. It's the namespace that's assumed if you interact with Kubernetes resources without specifying a namespace.

    Remember that Kubernetes doesn't require you to use the default namespace exclusively, it's just a starting point. You can create multiple namespaces to separate, organize, and manage different aspects of your applications.

    We will see how to create namespaces later in this blog.

  2. kube-node-lease: It is the heartbeat of the node. It is a system namespace and resource that is responsible for managing node leases. Node leases are used by the control plane components to determine the health and availability status of nodes in the cluster.

    It ensures that the control plane can accurately assess the status of nodes and make informed decisions regarding scheduling and workload distribution.

  3. kube-public: It contains the cluster information. It is a system namespace that is created by default in every cluster. It serves as a namespace accessible to all users, providing a space for resources that are accessible to all users and pods in the cluster, regardless of their namespace.

    It provides a designated space to share information that is relevant to the entire cluster without the need for explicit cross-namespace references.

  4. kube-system: It is reserved for the system, so we should not run our application here. It is a system namespace that contains essential control plane components and services that manage and maintain the health and operation of the Kubernetes cluster itself.

    Kube-system namespace contains the backbone of the Kubernetes cluster—components and services that keep the cluster operational, secure, and efficient. It's a key part of the Kubernetes architecture that demands careful management and attention.

To get the pods running in the default namespace,

kubectl get pods -n default

To get the lease object,

kubectl get lease -n kube-node-lease

To get the cluster information,

kubectl get cm -n kube-public

We can also create a namespace by using the command,

kubectl create ns <NAME>

To describe a namespace,

kubectl describe ns <NAME>

Namespaces can also be created in a declarative manner. Here is how,

To change context from the default namespace to some other namespace,

To delete a namespace,

kubectl delete ns <NAME>

So that was about namespaces. We covered various namespaces and various commands related to namespaces.

Connect with me to get more content around DevOps, CNCF, Golang and Open source.