0
0
Kubernetesdevops~15 mins

Creating custom namespaces in Kubernetes - Try It Yourself

Choose your learning style9 modes available
Creating custom namespaces
📖 Scenario: You are managing a Kubernetes cluster for a small company. To keep resources organized, you want to create a custom namespace called project-alpha. Namespaces help separate resources like pods and services so teams can work independently.
🎯 Goal: Learn how to create a custom namespace in Kubernetes using a YAML configuration file and apply it with kubectl.
📋 What You'll Learn
Create a YAML file defining a namespace named project-alpha
Use kubectl to apply the YAML file and create the namespace
Verify the namespace was created by listing all namespaces
💡 Why This Matters
🌍 Real World
Namespaces help organize and separate resources in Kubernetes clusters, making it easier to manage multiple projects or teams.
💼 Career
Knowing how to create and manage namespaces is essential for Kubernetes administrators and DevOps engineers to maintain clean and secure cluster environments.
Progress0 / 4 steps
1
Create a YAML file for the namespace
Create a file named namespace.yaml with the exact content below to define a namespace called project-alpha:
apiVersion: v1
kind: Namespace
metadata:
  name: project-alpha
Kubernetes
Need a hint?

Remember, the YAML file must start with apiVersion: v1 and kind: Namespace. The metadata section must have name: project-alpha.

2
Apply the namespace YAML file
Run the command kubectl apply -f namespace.yaml to create the project-alpha namespace in your Kubernetes cluster.
Kubernetes
Need a hint?

Use kubectl apply -f namespace.yaml exactly to create the namespace.

3
Verify the namespace creation
Run the command kubectl get namespaces to list all namespaces and confirm that project-alpha appears in the list.
Kubernetes
Need a hint?

Use kubectl get namespaces to see all namespaces including project-alpha.

4
Show the namespace in the output
Run kubectl get namespaces and ensure the output includes the line with project-alpha.
Kubernetes
Need a hint?

The output of kubectl get namespaces should list project-alpha among the namespaces.