0
0
Kubernetesdevops~10 mins

Creating custom namespaces in Kubernetes - Visual Walkthrough

Choose your learning style9 modes available
Process Flow - Creating custom namespaces
Write YAML file for Namespace
Run kubectl apply -f namespace.yaml
Kubernetes API Server receives request
Namespace resource created in cluster
kubectl get namespaces shows new namespace
Use namespace in pods/deployments
This flow shows how you create a custom namespace by writing a YAML file, applying it with kubectl, and then using it in your cluster.
Execution Sample
Kubernetes
apiVersion: v1
kind: Namespace
metadata:
  name: my-custom-namespace
This YAML defines a new Kubernetes namespace called 'my-custom-namespace'.
Process Table
StepCommand/ActionSystem ResponseResulting State
1Create namespace.yaml file with namespace definitionFile created locallynamespace.yaml exists with correct content
2kubectl apply -f namespace.yamlNamespace 'my-custom-namespace' createdNamespace resource added to cluster
3kubectl get namespacesLists all namespaces including 'my-custom-namespace'User sees new namespace in list
4Use namespace in pod/deployment specPods/deployments created in 'my-custom-namespace'Resources scoped to custom namespace
5kubectl delete namespace my-custom-namespaceNamespace and all resources inside deletedNamespace removed from cluster
💡 Namespace creation completes after kubectl apply; visible in namespace list and usable for resource scoping.
Status Tracker
VariableStartAfter Step 2After Step 3Final
namespace.yamlNot createdCreated with namespace definitionUnchangedUnchanged
Cluster NamespacesDefault namespaces onlyIncludes 'my-custom-namespace'Includes 'my-custom-namespace'Depends on deletion
Resources in 'my-custom-namespace'NoneNoneNoneCreated after deployment
Key Moments - 3 Insights
Why doesn't the namespace appear immediately after creating the YAML file?
Creating the YAML file only saves the definition locally. The namespace appears in the cluster only after running 'kubectl apply -f namespace.yaml' as shown in execution_table step 2.
Can I create pods in a namespace before it exists?
No, pods must be created after the namespace exists in the cluster. The namespace resource must be applied first (step 2), then pods can be created inside it (step 4).
What happens if I delete a namespace?
Deleting a namespace removes it and all resources inside it from the cluster, as shown in step 5 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what command creates the namespace resource in the cluster?
Akubectl get namespaces
Bkubectl apply -f namespace.yaml
Ckubectl delete namespace my-custom-namespace
DCreating the YAML file
💡 Hint
Check step 2 in the execution_table where the namespace is created.
At which step does the new namespace become visible when listing namespaces?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the system response in step 3 of the execution_table.
If you delete the namespace, what happens to the resources inside it?
AThey remain in the cluster
BThey move to the default namespace
CThey are deleted along with the namespace
DThey become inactive but stay allocated
💡 Hint
Refer to step 5 in the execution_table about namespace deletion.
Concept Snapshot
Creating a custom namespace:
- Write a YAML file with kind: Namespace and metadata.name
- Run 'kubectl apply -f filename.yaml' to create it
- Verify with 'kubectl get namespaces'
- Use the namespace in pod/deployment specs
- Deleting the namespace removes all contained resources
Full Transcript
To create a custom namespace in Kubernetes, first write a YAML file defining the namespace with kind: Namespace and a unique name. Then apply this file using 'kubectl apply -f'. This sends the request to the Kubernetes API server, which creates the namespace resource in the cluster. You can verify the namespace exists by listing namespaces with 'kubectl get namespaces'. After creation, you can create pods or deployments inside this namespace by specifying it in their specs. If you delete the namespace, all resources inside it are also deleted. This process helps organize and isolate resources in your cluster.