Challenge - 5 Problems
Namespace Context Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of switching namespace context?
You run the command
kubectl config set-context --current --namespace=dev. What will be the output or effect of this command?Attempts:
2 left
💡 Hint
Think about what the command does to the current context and if it outputs messages.
✗ Incorrect
The command changes the namespace of the current context silently without output. It does not create or delete contexts or print confirmation messages.
💻 Command Output
intermediate2:00remaining
What happens if you switch to a non-existent namespace?
You run
kubectl config set-context --current --namespace=unknown but the namespace 'unknown' does not exist. What is the result?Attempts:
2 left
💡 Hint
Does kubectl validate namespace existence when setting context namespace?
✗ Incorrect
kubectl does not check if the namespace exists when setting the context namespace. It just updates the config.
🔀 Workflow
advanced3:00remaining
Correct sequence to switch namespace context and verify
Arrange the following commands in the correct order to switch the current kubectl context to namespace 'test' and verify the change.
Attempts:
2 left
💡 Hint
First switch namespace, then check pods in that namespace, then verify namespace in context, finally list all namespaces.
✗ Incorrect
You first set the namespace in the current context, then get pods to see resources in that namespace, then verify the namespace setting, and finally list all namespaces.
❓ Troubleshoot
advanced2:00remaining
Why does kubectl still show pods from default namespace after switching?
You ran
kubectl config set-context --current --namespace=prod but kubectl get pods still shows pods from the 'default' namespace. What is the most likely cause?Attempts:
2 left
💡 Hint
Check if any command line flags override the context namespace.
✗ Incorrect
The
--namespace flag in kubectl commands overrides the context namespace setting. If you specify --namespace=default, it will show pods from default namespace regardless of context.✅ Best Practice
expert3:00remaining
Best practice to switch namespace context safely in scripts
You want to write a script that switches the kubectl context namespace to 'staging' only if the namespace exists. Which approach is best?
Attempts:
2 left
💡 Hint
Think about avoiding errors in scripts by checking resource existence first.
✗ Incorrect
Checking if the namespace exists before switching prevents errors or misconfigurations in scripts. Creating or deleting contexts unnecessarily is not recommended.