sajad torkamani

What is a namespace?

A namespace is like a virtual cluster inside a K8s cluster that lets you divide your cluster resources between multiple teams or applications.

When you create a resource like a Pod or Service, you can assign them a namespace so that they don’t conflict with resources with the same name but from other namespaces.

Why use a namespace?

  • For a larger application where you have multiple teams and you want each team tohave their own namespace.
  • To separate environments: development, staging, production, etc.
  • To enforce resource quotas: different CPU / memory allocations for each namespace.

Default namespaces

  • kube-default: Contains resources you created which you didn’t assign to a particular namespace.
  • kube-system: For internal K8s components such as kube-dns.
  • kube-node-lease: Contains Lease objects associated with each node. Node leases allow kubelet to send heartbeats to the control plane so that the control plane can detect node failure.
  • kube-public: Contains publicly visible resources such as information about the cluster

Recipes

List namespaces

kubectl get namespaces

List namespace resources

kubectl get pods -n <namespace>

Create a new namespace

kubectl create namespace my-namespace

Change default namespace

Install the kubens tool.

brew install kubes

Change default namespace

kubens <some-namespace>s
Tagged: Kubernetes