Video Thumbnail for Lesson
4.1: Namespace

Namespace

In Kubernetes, namespaces are used to divide cluster resources between multiple users or teams. They provide a scope for resource names, which helps in avoiding name conflicts and allows better organization and management of resources.

Namespaces are ideal for environments with multiple teams or projects within the same cluster.

Hands-On: Working with Namespaces

Let's create, apply, and delete namespaces using practical commands.

1. Create a Namespace Using the CLI

First, we can create a namespace using the kubectl command-line tool.

# task 01-create-namespace
# - Create a namespace in the cluster
kubectl create namespace 04--namespace-cli

2. Apply Namespace Configuration

Next, we'll apply a namespace configuration using a YAML file. This allows us to define namespaces declaratively.

# Namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: 04--namespace-file
# task 02-apply-namespace
# - Apply the namespace configuration to the cluster
kubectl apply -f Namespace.yaml

3. Delete the Namespaces

Finally, clean up your cluster by deleting the namespaces created.

# task 03-delete-namespaces
#  - Delete the namespace.
kubectl delete namespace 04--namespace-cli
kubectl delete -f Namespace.yaml