Namespaces

Create

Use manifest to create:

apiVersion: v1
kind: Namespace
metadata:
  name: dev

Commands:

kubectl create -f namespace-dev.yaml
kubectl create namespace dev

Pods in Namespace

To place pods in selected namespace add it to their manifest:

apiVersion: v1
kind: Pod       
metadata: 
  namespace: dev
  name: myapp-pod
spec:
  containers:
    - name: nginx-container
      image: nginx

Viewing Namespace Contents

Write the target namespace to get pods from:

kubectl get pods --namesapce=dev

Changing namespace in the current context of kubectl to dev:

kubectl config set-context $(kubectl config current-context) --namespace=dev 

List pods in all namespaces:

kubectl get pods --all-namespaces