Bird
Raised Fist0
Kubernetesdevops~20 mins

Creating custom namespaces in Kubernetes - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Namespace Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of Namespace Creation Command
What is the output of running this command in a Kubernetes cluster?

kubectl create namespace dev-team
Kubernetes
kubectl create namespace dev-team
Acommand not found: kubectl
BError from server (AlreadyExists): namespaces "dev-team" already exists
CNo resources found.
Dnamespace/dev-team created
Attempts:
2 left
💡 Hint
Think about what kubectl outputs when a namespace is successfully created.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Kubernetes Namespaces
Which option best describes the purpose of creating custom namespaces in Kubernetes?
ATo create a backup of the cluster configuration
BTo increase the CPU and memory limits of pods automatically
CTo isolate resources and organize cluster objects logically
DTo deploy applications faster by skipping validations
Attempts:
2 left
💡 Hint
Think about how namespaces help manage resources in a shared environment.
❓ Configuration
advanced
2:00remaining
Correct YAML for Custom Namespace
Which YAML configuration correctly creates a namespace named qa-environment?
A
apiVersion: v1
kind: Namespace
metadata:
  name: qa-environment
B
apiVersion: v1
kind: Namespace
metadata:
  namespace: qa-environment
C
apiVersion: v1
kind: Namespace
metadata:
  name: qa_environment
D
apiVersion: v1
kind: Namespace
metadata:
  name: qa-environment
spec:
  replicas: 3
Attempts:
2 left
💡 Hint
Check the correct field name under metadata for naming namespaces.
❓ Troubleshoot
advanced
2:00remaining
Troubleshooting Namespace Creation Error
You run kubectl create namespace test-env but get this error:

Error from server (Forbidden): namespaces "test-env" is forbidden: User "developer" cannot create resource "namespaces" in API group "" at the cluster scope

What is the most likely cause?
AThe namespace 'test-env' already exists
BThe user 'developer' lacks permission to create namespaces cluster-wide
CThe kubectl command is misspelled
DThe Kubernetes API server is down
Attempts:
2 left
💡 Hint
Focus on the 'Forbidden' and 'cannot create resource' parts of the error.
🔀 Workflow
expert
2:30remaining
Namespace Creation and Resource Deployment Order
You want to deploy an application in a new namespace called staging. Which is the correct order of commands to achieve this?
A3,1,4,2
B1,3,4,2
C1,4,3,2
D3,4,1,2
Attempts:
2 left
💡 Hint
You must create the namespace before deploying resources into it.

Practice

(1/5)
1. What is the main purpose of creating a custom namespace in Kubernetes?
easy
A. To increase the number of nodes in the cluster
B. To group and isolate resources for better organization
C. To speed up container image downloads
D. To automatically update all pods

Solution

  1. Step 1: Understand Kubernetes namespaces

    Namespaces help organize and isolate resources within the same cluster.
  2. Step 2: Identify the purpose of custom namespaces

    Custom namespaces separate projects, teams, or environments for clarity and management.
  3. Final Answer:

    To group and isolate resources for better organization -> Option B
  4. Quick Check:

    Namespaces = Organize resources [OK]
Hint: Namespaces isolate resources logically, not physically [OK]
Common Mistakes:
  • Thinking namespaces add nodes
  • Confusing namespaces with pods
  • Believing namespaces speed up downloads
2. Which YAML snippet correctly defines a custom namespace named dev-team?
easy
A. apiVersion: v1\nkind: Namespace\nmetadata:\n name: dev-team
B. apiVersion: v1\nkind: Pod\nmetadata:\n name: dev-team
C. apiVersion: apps/v1\nkind: Namespace\nmetadata:\n name: dev-team
D. apiVersion: v1\nkind: Service\nmetadata:\n name: dev-team

Solution

  1. Step 1: Identify correct apiVersion and kind for namespace

    The correct apiVersion is 'v1' and kind is 'Namespace' for creating namespaces.
  2. Step 2: Check metadata name field

    The metadata name must be the desired namespace name, here 'dev-team'.
  3. Final Answer:

    apiVersion: v1\nkind: Namespace\nmetadata:\n name: dev-team -> Option A
  4. Quick Check:

    Namespace YAML = apiVersion v1 + kind Namespace [OK]
Hint: Namespace kind is always 'Namespace' with apiVersion 'v1' [OK]
Common Mistakes:
  • Using wrong kind like Pod or Service
  • Using wrong apiVersion like apps/v1
  • Missing metadata name field
3. What will be the output of the command kubectl get namespaces after applying this YAML?
apiVersion: v1
kind: Namespace
metadata:
  name: test-env
medium
A. Only default namespaces are shown, 'test-env' is missing
B. Shows an error: namespace 'test-env' already exists
C. No output, command hangs
D. Lists all namespaces including 'test-env'

Solution

  1. Step 1: Apply the namespace YAML

    Applying the YAML creates a new namespace named 'test-env' in the cluster.
  2. Step 2: Run 'kubectl get namespaces'

    This command lists all namespaces, including the newly created 'test-env'.
  3. Final Answer:

    Lists all namespaces including 'test-env' -> Option D
  4. Quick Check:

    kubectl get namespaces shows all namespaces [OK]
Hint: New namespaces appear in 'kubectl get namespaces' output [OK]
Common Mistakes:
  • Expecting error if namespace exists (it won't if new)
  • Thinking command hangs
  • Assuming only default namespaces show
4. You tried to create a namespace with this YAML but got an error:
apiVersion: v1
kind: Namespace
metadata:
  name: 123team

What is the likely cause?
medium
A. Namespace names cannot start with a number
B. apiVersion 'v1' is incorrect for namespaces
C. Missing 'labels' field in metadata
D. Namespace kind should be 'Project'

Solution

  1. Step 1: Check namespace naming rules

    Namespace names must start with a letter and contain only lowercase letters, numbers, and dashes.
  2. Step 2: Identify invalid name

    The name '123team' starts with a number, which is invalid and causes the error.
  3. Final Answer:

    Namespace names cannot start with a number -> Option A
  4. Quick Check:

    Namespace name rules forbid starting with digits [OK]
Hint: Namespace names must start with a letter, not a number [OK]
Common Mistakes:
  • Thinking apiVersion v1 is wrong
  • Believing labels are mandatory
  • Using wrong kind like 'Project'
5. You want to create two namespaces, dev and prod, and ensure pods in dev cannot access services in prod. Which approach is best?
hard
A. Create namespaces and use different node pools for each
B. Create namespaces and label pods with 'access=restricted' only
C. Create both namespaces and use NetworkPolicies to restrict access
D. Create namespaces and deploy all pods in the default namespace

Solution

  1. Step 1: Create separate namespaces

    Namespaces 'dev' and 'prod' isolate resources logically in the cluster.
  2. Step 2: Use NetworkPolicies to control traffic

    NetworkPolicies can restrict pod-to-service communication between namespaces effectively.
  3. Final Answer:

    Create both namespaces and use NetworkPolicies to restrict access -> Option C
  4. Quick Check:

    Namespaces + NetworkPolicies = access control [OK]
Hint: Use NetworkPolicies with namespaces for access control [OK]
Common Mistakes:
  • Assuming labels alone restrict network access
  • Deploying all pods in default namespace ignores isolation
  • Using node pools does not isolate network traffic
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard