Namespaces || Kubernetes

Namespaces || Kubernetes

what are Namespaces?

Namespaces in Kubernetes offer a way to isolate groupings of resources inside a single cluster. Resources' names must be distinct both inside and between namespaces, but not both. Only namespaced items (such as deployments, services, etc.) and not cluster-wide objects (such as storage classes, nodes, persistent volumes, etc.) may use namespace-based scoping.

When to use Namespaces?

  • Namespaces are designed to be used in settings where there are several users dispersed across numerous teams or projects. You shouldn't have to build or even consider namespaces for clusters with a few to tens of users. As soon as you require the functionality that namespaces offer, start using them.

  • Names have a range thanks to namespaces. Resources' names must be distinct both inside and between namespaces, but not both. Each Kubernetes resource can only be in one namespace, and namespaces cannot be nested within one another.

  • Use labels to identify resources inside the same namespace instead of creating distinct namespaces for slightly different resources, such as successive iterations of the same piece of software.

Pros of using Namespaces

  • Default namespace: Avoiding to use it.

  • Resource Limits: CPU and memory restrictions per application or microservice (1 x ns) Nice to include in PROD to prevent defective processes/apps from using the whole namespace/cluster resources.

  • Monitoring: We may filter metrics and dashboard displays by namespace using Prometheus and Grafana.

  • Centralized Logs & Alert based on logs: Filtering logs more easily per app or microservice using Elastic Fluent Kibana (EFK) and logs filters (1 x namespace).

  • Operations: Automation, upkeep, and deployment (using Spinnaker and Jenkins).

Kubernetes Namespaces

  • default: This namespace is built within Kubernetes so you can use your new cluster right away without first establishing one.

  • kube-node-lease: Each node's related Lease objects are stored in this namespace. The kubelet can communicate heartbeats over node leases so that the control plane can identify node failure.

  • kube-public: Any client, including one who is not signed in, can read this namespace. This namespace is primarily designated for cluster use, if some resources need to be accessible to the general public throughout the whole cluster. This namespace's public feature is only a convention and not a necessity.

  • kube-system: The namespace used by Kubernetes to construct objects.

Namespaces Commands

kubectl get namespace
NAME              STATUS   AGE
default           Active   1d
kube-node-lease   Active   1d
kube-public       Active   1d
kube-system       Active   1d