📖 Scenario: You are managing a Kubernetes cluster. Namespaces help organize resources like pods and services. By default, Kubernetes creates some namespaces automatically.Understanding these default namespaces helps you know where your resources live and how to manage them.
🎯 Goal: You will list the default namespaces in a Kubernetes cluster and display their names.
📋 What You'll Learn
Use kubectl commands to interact with the cluster
List all namespaces
Extract only the namespace names
Print the list of default namespaces
💡 Why This Matters
🌍 Real World
Namespaces help organize and separate resources in a Kubernetes cluster, making management easier and safer.
💼 Career
Understanding default namespaces is essential for Kubernetes administrators and DevOps engineers to manage cluster resources effectively.
Progress0 / 4 steps
1
List all namespaces
Run the command kubectl get namespaces to list all namespaces in the cluster.
Kubernetes
Hint
Use kubectl get namespaces to see all namespaces.
2
Extract only the namespace names
Use kubectl get namespaces -o jsonpath='{.items[*].metadata.name}' to get only the names of the namespaces.
Kubernetes
Hint
Use the -o jsonpath= option to extract specific fields.
3
Format the output for readability
Add | tr ' ' '\n' to the previous command to print each namespace name on a new line.
Kubernetes
Hint
Use tr command to replace spaces with new lines.
4
Display the default namespaces
Run the full command kubectl get namespaces -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' and print the output to show the default namespaces.
Kubernetes
Hint
The output should list these default namespaces: default, kube-system, kube-public, and kube-node-lease.
Practice
(1/5)
1. What is the purpose of namespaces in Kubernetes?
easy
A. To replace pods in the cluster
B. To increase the CPU speed of nodes
C. To organize resources into separate groups within a cluster
D. To store container images
Solution
Step 1: Understand what namespaces do
Namespaces help group and isolate resources in a Kubernetes cluster.
Step 2: Identify the correct purpose
They do not affect CPU speed, store images, or replace pods.
Final Answer:
To organize resources into separate groups within a cluster -> Option C
Quick Check:
Namespaces organize resources [OK]
Hint: Namespaces group resources logically in Kubernetes [OK]
Common Mistakes:
Thinking namespaces speed up nodes
Confusing namespaces with image storage
Believing namespaces replace pods
2. Which of the following is a default namespace in Kubernetes?
easy
A. user-space
B. production
C. development
D. kube-system
Solution
Step 1: Recall default namespaces
Kubernetes provides default namespaces like default, kube-system, and kube-public.
Step 2: Identify the correct default namespace
kube-system is a default namespace for system components, while others are user-defined.
Final Answer:
kube-system -> Option D
Quick Check:
kube-system is default namespace [OK]
Hint: Remember kube-system for system pods [OK]
Common Mistakes:
Assuming production is default
Confusing user namespaces with defaults
Thinking development is built-in
3. What will the command kubectl get pods -n default show?
medium
A. Pods in the default namespace
B. All pods in all namespaces
C. Pods in the kube-system namespace
D. No pods, because default namespace is empty
Solution
Step 1: Understand the command syntax
kubectl get pods -n default lists pods in the namespace named default.
Step 2: Identify the namespace targeted
The -n default flag limits output to the default namespace only.
Final Answer:
Pods in the default namespace -> Option A
Quick Check:
kubectl -n default shows default pods [OK]
Hint: -n specifies namespace for kubectl commands [OK]
Common Mistakes:
Thinking it shows pods from all namespaces
Confusing default with kube-system
Assuming default namespace is always empty
4. You run kubectl get pods but get an error: error: namespace "defaultt" not found. What is the likely cause?
medium
A. Pods do not exist in any namespace
B. The namespace name is misspelled
C. kubectl is not installed
D. The cluster is down
Solution
Step 1: Analyze the error message
The error says namespace "defaultt" not found, indicating a typo.
Step 2: Check command usage
Likely the user typed defaultt instead of default as namespace.
Final Answer:
The namespace name is misspelled -> Option B
Quick Check:
Namespace typo causes not found error [OK]
Hint: Check spelling of namespace names carefully [OK]
Common Mistakes:
Assuming pods don't exist anywhere
Blaming kubectl installation
Thinking cluster is down without checking
5. You want to deploy an app only visible to system components. Which default namespace should you use?
hard
A. kube-system
B. kube-public
C. default
D. custom-namespace
Solution
Step 1: Understand namespace roles
kube-system holds system components and is isolated from normal user apps.
Step 2: Choose namespace for system visibility
Deploying in kube-system makes the app visible only to system components.
Final Answer:
kube-system -> Option A
Quick Check:
System apps use kube-system namespace [OK]
Hint: Use kube-system for system-only apps [OK]
Common Mistakes:
Using default namespace for system apps
Choosing kube-public which is for public info
Using a custom namespace without system access
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.