Kubernetes namespaces
what is a namespace
Namespaces are virtual clusters backed by the same physical cluster. Kubernetes objects like pods and containers live in namespaces, essentially a namespaces is a way to organize objects in your kubernetes cluster
Namespaces is a very useful tool if you have many different type of applications running or if you have multiple teams that share the cluster.
working with namespaces$ kubectl get namespaces
NAME STATUS AGE
default Active 21h
kube-node-lease Active 21h
kube-public Active 21h
kube-system Active 21h
All Kubernetes clusters have a default namespace. This is used when no other namespace is defined.
kubeadm also creates the kube-system namespace for system components, actually avoid creating namespaces starting with kube* because their might have created from a Kubernetes component.
Another thing you need to be aware is that kubectl command you might want to specify a namespace, if you don't the default namespace is assumed
The following command will list the pods of the default name space$ kubectl get pods
The following command will list the pods of the kube-system$ kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-69496d8b75-vp9m9 1/1 Running 1 21h
calico-node-2x98n 1/1 Running 1 21h
calico-node-67tfn 1/1 Running 2 21h
calico-node-k7ff8 1/1 Running 1 21h
coredns-74ff55c5b-6428b 1/1 Running 1 21h
coredns-74ff55c5b-q462g 1/1 Running 1 21h
etcd-konstantinospatronas3c.mylabserver.com 1/1 Running 1 21h
kube-apiserver-konstantinospatronas3c.mylabserver.com 1/1 Running 1 21h
kube-controller-manager-konstantinospatronas3c.mylabserver.com 1/1 Running 1 21h
kube-proxy-7ck7p 1/1 Running 1 21h
kube-proxy-rxkm7 1/1 Running 1 21h
kube-proxy-vgf69 1/1 Running 1 21h
kube-scheduler-konstantinospatronas3c.mylabserver.com 1/1 Running 1 21h
if you are not sure for the namespace that a pod might exist you can list all pods from all namespaces$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-69496d8b75-vp9m9 1/1 Running 1 21h
kube-system calico-node-2x98n 1/1 Running 1 21h
kube-system calico-node-67tfn 1/1 Running 2 21h
To create a namespace is very easy$ kubectl create namespace test-space
namespace/test-space created