CKAD field manual

k8s Namespace YAML example

Almost every exam question is in a namespace. Set it once, then stop forgetting -n.

Separate platforms float above the same clouds, each with its own towers; a ship crosses between them. Separate platforms float above the same clouds, each with its own towers; a ship crosses between them.
Create and switch
kubectl create ns app
kubectl config set-context --current --namespace=app
kubectl config view --minify | grep namespace
YAML
apiVersion: v1
kind: Namespace
metadata:
  name: app
  labels:
    env: exam
Inspect
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

Practice these objects on a live cluster →