Namespaces - neerajk555/Kubernetes GitHub Wiki
Let’s walk through creating and using namespaces with a simple Pod deployment.
Step 1: Create a Namespace
kubectl create namespace dev-team
Check if it's created:
kubectl get namespaces
Step 2: Deploy a Pod into that Namespace
Create a file nginx-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
namespace: dev-team #deploy into dev-team namespace
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
Apply it: kubectl apply -f nginx-pod.yaml
Step 3: Verify the Pod is Running
kubectl get pods -n dev-team
If you try kubectl get pods without -n, it’ll check only in the default namespace.
Step 4: Deploy Another Pod in a Different Namespace
kubectl create namespace qa-team
Now run another pod with the same name but in the new namespace:
# nginx-qa.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod # same name is OK because different namespace
namespace: qa-team
spec:
containers:
- name: nginx
image: nginx
Apply it: kubectl apply -f nginx-qa.yaml
Verify:kubectl get pods -n qa-team
Step 5: Clean Up
kubectl delete namespace dev-team
kubectl delete namespace qa-team