CKAD field manual
k8s Namespace YAML example
Almost every exam question is in a namespace. Set it once, then stop forgetting -n.
kubectl create ns app
kubectl config set-context --current --namespace=app
kubectl config view --minify | grep namespace
apiVersion: v1
kind: Namespace
metadata:
name: app
labels:
env: exam
kubectl get ns
kubectl get all -n app
kubectl api-resources --namespaced=true
kubectl api-resources --namespaced=false
Fields
- kubectl create ns
- Creates the Namespace. It does not switch you into it.
- kubectl config set-context
- --current --namespace=app. After this, bare kubectl get po is that ns.
- kubectl get ns
- Namespaces are cluster-scoped. There is no -n on this command.
Watch
- create ns does not change your context. Default is still default until set-context.
- Nodes, PV, Namespace, ClusterRole are cluster-scoped. -n is ignored or rejected.
- Deleting a Namespace deletes everything in it. There is no undo.
Official docs Namespaces