In Kubernetes, namespaces provide a mechanism for isolating groups of resources within a single cluster. You can think of a namespace as a virtual cluster built on top of the same physical cluster.
Namespaces are intended for use in environments with many users spread across multiple teams, or projects. Resources like Pods, Services, and Deployments are created within a specific namespace. If no namespace is specified, they are placed in the default namespace.
Namespaces are important to use because they help solve several problems:
kubectl get pods then all pods will come up, but if you are a backend developer then other than backend pods all pods are irrelevant to you.kubectl create namespace backend-teamkubectl get namespaceskubectl get pods -n my-namespaceapiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: backend-team
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80kubectl apply -f deployment-ns.ymlkubectl get deployment -n backend-teamkubectl get pods -n backend-teamkubectl config set-context --current --namespace=backend-teamkubectl get podskubectl config set-context --current --namespace=default