Namespaces are a way to organize clusters into virtual sub-clusters — they can be helpful when different teams or projects share a Kubernetes cluster.
Namespaces allow to split-up resources into different groups. Resource names should be unique in a namespace. We can use namespaces to create multiple environments like dev, staging and production etc.
Kubernetes comes with three namespaces out-of-the-box. They are:
1. default: this is the namespace that is referenced by default for every Kubernetes command, and where every Kubernetes resource is located by default.
Until new namespaces are created, the entire cluster resides in ‘default’.
2. kube-system: Used for Kubernetes components
3. kube-public: Used for public resources.
To create namespace
> kubectl create ns development
> kubectl create ns production
To view namespaces
> kubectl get namespaces
> kubectl get ns
Define namespace in a yaml file:
metadata:
name : pod4
namespace: development
To view namespace along with associated pods
> kubectl get pods --all-namespaces
To change default namespace
>kubectl config set-context --current --namespace=development
To delete a namespace
> kubectl delete namespace development
NOTE:Everything in the namespace including all services, running pods, and artifacts will be deleted




0 comments:
Post a Comment