0
0
Kubernetesdevops~15 mins

Switching namespace context in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Switching Namespace Context in Kubernetes
📖 Scenario: You are managing multiple projects in Kubernetes. Each project uses a different namespace to keep resources separate. You want to switch your command-line context to work inside a specific namespace easily.
🎯 Goal: Learn how to switch the current Kubernetes context to a different namespace using kubectl. This helps you run commands inside the right project space without typing the namespace every time.
📋 What You'll Learn
Use kubectl commands to interact with Kubernetes
Understand namespaces as separate project spaces
Switch the current context namespace using kubectl config set-context
Verify the current namespace with kubectl config view --minify
💡 Why This Matters
🌍 Real World
In real Kubernetes projects, namespaces help separate environments like development, testing, and production. Switching namespaces quickly lets you work in the right environment without mistakes.
💼 Career
DevOps engineers and system administrators often switch namespaces to manage resources efficiently and avoid accidental changes in the wrong environment.
Progress0 / 4 steps
1
Check the current Kubernetes context namespace
Run the command kubectl config view --minify --output 'jsonpath={..namespace}' to see the current namespace your kubectl context is set to.
Kubernetes
Need a hint?

This command shows the namespace your kubectl commands will use by default.

2
Set the current context to use the development namespace
Use the command kubectl config set-context --current --namespace=development to switch your current context namespace to development.
Kubernetes
Need a hint?

This command changes the default namespace for your current kubectl context.

3
Verify the namespace has switched to development
Run kubectl config view --minify --output 'jsonpath={..namespace}' again to confirm the namespace is now development.
Kubernetes
Need a hint?

Run the same command as Step 1 to check the namespace again.

4
Display the current namespace in a friendly message
Use echo with command substitution to print: Current namespace is: development by running echo "Current namespace is: $(kubectl config view --minify --output 'jsonpath={..namespace}')".
Kubernetes
Need a hint?

This prints a clear message showing the active namespace.