Post

Kubernetes - Namespaces

Lab assignment for creating namespaces using kubectl

Kubernetes - Namespaces

Prerequisites

  • Kubernetes
  • kubectl

Assignment

  • Lets start by creating a pod in the default namespace and then in a user defined namespace.

1️⃣ List all the resources created in the K8 cluster and review the existing namespaces.

1
kubectl get all -A

2️⃣ List all the namespaces.

1
kubectl get namespaces

3️⃣ Run a pod without specifying a namespace run in the default namespace.

1
kubectl run nginx --image=nginx

4️⃣ Create a user defined namespace and run a pod inside that namespace.

1
2
3
kubectl create namespace mynamespace
kubectl -n mynamespace run nginx --image=nginx
kubectl -n mynamespace get pods

5️⃣ Change the default namespace from default to a user defined namespace.

1
2
kubectl config set-context --current --namespace=mynamespace
kubectl config view

CleanUp

1
kubectl delete namespace mynamespace --now
This post is licensed under CC BY 4.0 by the author.