kubernetes namespaces

  • kubernetes supports multiple virtual clusters in the same physical cluster
  • namespace == virtual cluster
  • can split objects in distinct groups (kubernetes label cannot)
  • objects are unique inside a namespace, i.e. objects with the same name can exist in two distinct namespace
  • can allocate resource quotas per namespace
  • when no namespace is specified, the default namespace is used
 kubectl get namespaces
NAME                   STATUS   AGE
default                Active   12d
kube-node-lease        Active   12d
kube-public            Active   12d
kube-system            Active   12d
kubernetes-dashboard   Active   12d
  • kubectx and kubens: tools to easily switch k8s clusters and namespaces
  • ⚠️ namespace cannot contain a dot .
  • create an object in a namespace, add the metadata.namespace value:
---
apiVersion: v1
kind: Pod
metadata:
  name: foobar
  namespace: popo
  labels:
    app: azerty
spec:
  # ...

LimitRanges

It’s possible to configure limit per namespace:

---
apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit-range
spec:
  limits:
    - default:
        memory: 512Mi
      defaultRequest:
        memory: 256Mi
      max:
        memory: 1Gi
      min:
        memory: 200Mi
      type: Container

ResourceQuota

Limit total resource usage for a namespace:

---
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-resources
spec:
  hard:
    requests.cpu: "1"
    requests.memory: 1Gi
    limits.cpu: "2"
    limits.memory: 2Gi