Skip to main content

Command Palette

Search for a command to run...

Namespaces Kubernetes

Updated
3 min read

What is a Namespace?

Namespace provides a mechanism for isolating groups of resources within a single cluster.

  • Names of resources need to be unique within a namespace, but not across a namespace.

  • Namespace-based scoping is applicable only for namespaced objects such as deployment, services etc and not for cluster-wide objects such as storage class, nodes, persistent volumes etc.

When to use multiple namespaces

  • Namespaces are intended for use in environments with many users spread across multiple teams or projects. For clusters with a few to tens of users, you should not need to create or think about a namespace at all.

  • Namespace provide a scope for names, names of resources need to be unique within a namespace, but not across a namespace. Namespace are a way to divide cluster resources between multiple users( resource quotat)

  • It is not necessary to use multiple namespaces to separate slightly different resources,such as different versions of the sasme software: use labes to distinguish resources within the same namespace.

Types of Namepsace

  • Default: Kubernetes includes this namespace so that you can start using your new cluster without first creating a namespace.

  • Kube-node-lease: This namespace holds the lease object associated with each node. Node leases allow the kubelet to send heartbeats so that the control plane can detect node failure

  • Kube-public: This namespace is readable by all clients (including those not authenticated). This namespace is mostly reserved for cluster usage, in case 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.

  • Kube-system: The namespace for objects created by the Kubernetes system.

Namespace Commands and example

kubectl get namespaces

[node1 ~]$ kubectl get namespace
NAME              STATUS   AGE
default           Active   3m9s
kube-node-lease   Active   3m9s
kube-public       Active   3m9s
kube-system       Active   3m9s
[node1 ~]$
[node1 ~]$ kubectl get namespace kube-system -o wide
NAME          STATUS   AGE
kube-system   Active   5m9s

create namespace new_namespace_name

a-z0-9]([-a-z0-9]*[a-z0-9])?')
[node1 ~]$  kubectl create namespace mehdiproject
namespace/mehdiproject created

[node1 ~]$  kubectl get namespace
NAME              STATUS   AGE
default           Active   10m
kube-node-lease   Active   10m
kube-public       Active   10m
kube-system       Active   10m
mehdiproject      Active   27s
[node1 ~]$

kubectl get pods --namespace=<namespace_name>

here pods running are Kubernetes related system related pods

[node1 ~]$ kubectl get pods -n  kube-system -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP             NODE    NOMINATED NODE   READINESS GATES
coredns-5d78c9869d-4mtnd        1/1     Running   0          5m3s    10.5.0.3       node1   <none>           <none>
coredns-5d78c9869d-rfbpd        1/1     Running   0          5m3s    10.5.0.4       node1   <none>           <none>
etcd-node1                      1/1     Running   0          5m12s   192.168.0.23   node1   <none>           <none>
kube-apiserver-node1            1/1     Running   0          5m18s   192.168.0.23   node1   <none>           <none>
kube-controller-manager-node1   1/1     Running   0          5m10s   192.168.0.23   node1   <none>           <none>
kube-proxy-96qph                1/1     Running   0          5m3s    192.168.0.23   node1   <none>           <none>
kube-proxy-gmhww                1/1     Running   0          4m11s   192.168.0.21   node3   <none>           <none>
kube-proxy-qvnws                1/1     Running   0          4m31s   192.168.0.22   node2   <none>           <none>
kube-router-kbrcp               1/1     Running   0          5m3s    192.168.0.23   node1   <none>           <none>
kube-router-nwwn6               1/1     Running   0          4m11s   192.168.0.21   node3   <none>           <none>
kube-router-s644b               1/1     Running   0          4m31s   192.168.0.22   node2   <none>           <none>
kube-scheduler-node1            1/1     Running   0          5m18s   192.168.0.23   node1   <none>           <none>
[node1 ~]$

More from this blog

Welcome to Devops Learning !!!!

24 posts