Certified Kubernetes Administrator (CKA) · Free practice question 4 of 12
Setting the default namespace in a context
An engineer at Merriden Toys works mostly in namespace inventory and is tired of typing -n inventory. Which command makes inventory the default namespace for the current kubeconfig context?
- A.kubectl namespace set inventory --default --context=current
- B.export KUBE_NAMESPACE=inventory
- C.kubectl config use-context inventory
- D.kubectl config set-context --current --namespace=inventory
Show answer and explanation
Correct answer: D. kubectl config set-context --current --namespace=inventory
Why: Each kubeconfig context stores a cluster, a user and an optional namespace; set-context --current --namespace changes the namespace of the active context. use-context switches to a context with that name, kubectl has no namespace set command, and kubectl does not read a KUBE_NAMESPACE variable.
More free Certified Kubernetes Administrator (CKA) questions
- Drain flags for DaemonSets and emptyDir
- CronJob concurrencyPolicy Forbid
- Listing cluster-scoped API resources
- Session affinity by client IP
- Pod dnsPolicy Default versus ClusterFirst
- Raw block volumes with volumeMode
- Debugging a node with kubectl debug
- CreateContainerConfigError from missing ConfigMap
- Approving a client CertificateSigningRequest
- NetworkPolicy ipBlock with except
- Restoring a PVC from a VolumeSnapshot