Kubernetes basics - Namespace

Page content

Namespace

As I worte before, namespace is kind of logical boundary. Normaly, objects in namesapce A can’t communicate with objects in namespace B. So far, all objects are deployed in namespace default. We tagged name to a objects, and in the same namespaces object can be refered by its name label.

Create a namespace

kubectl create namespace dev
# change namespace permanently
kubectl config set-context $(kubectl config current-context) --namespace=dev
# My note
kubectl config current-context #microk8s

Or we can define namespace in YAML file also.

apiVersion: v1
kind: Namespace
metadata:
  name: dev

Create object in a namespace

In metadata section, you can define a namespace of the services explicitly.

metadata:
  namespace: dev

or option -n dev or --namespace=dev.