Cover image for Define your Kubernetes namespaces now!

Define your Kubernetes namespaces now!

adipolak profile image Adi Polak Updated on ・2 min read

Yeah, but why?

Namespaces help us divide the cluster resources between multiple users, as well as help split the resource quote.
This is important for when we want to use Kubernetes in production and share the cluster with many products/teams.

How do we do it?


  1. Kubernetes cluster - Quick start with aks
  2. Kubectl command line installed

Define the namespace using a YAML file -:

  "apiVersion": "v1",
  "kind": "Namespace",
  "metadata": {
    "name": "development",
    "labels": {
        "name": "development"

In the example, we call the namespace - development.
Name the file - namespace-dev.json

From the command line, run:

kubectl create -f namespace-dev.json

This command will actually create the namespace.

Check yourself with this command - it will show you all the namespace:

kubectl get namespaces --show-labels

Let's spin pods. But first, check what already exists:

kubectl config view

Get the current context:

kubectl config current-context

Let's say we got back dev_cluster as the current context.
This will return the cluster context name and we'll use it to define the development namespace for our context:

Use set-context to set the context with new name dev under the namespsace of development:

kubectl config set-context dev --namespace=development \
  --cluster=dev_cluster \

Switch to the new context:

kubectl config use-context dev

Now everything you'll do will take place in this context with the defined namespace.

This was K8s namespaces in under 2 min, part of K8s bitesize series.

Posted on by:

adipolak profile

Adi Polak


1 out of 25 influential women in Software Development according to Apiumhub. I am a software developer who would like to learn more!


Editor guide

Yep! This helps keep my OCDs in check!

It's similar to docker-composes, container names. I am pretty finicky about those as well. 😅

An awesome read!


Thank you, Rohan!