60DaysOfK8s – Day 8 Namespace

Within the same namespace, Each object in your cluster has a Name that is unique for that type of resource. Every Kubernetes object also has a UID that is unique across your whole cluster. This is generated by the system automatically.

Namespace

Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.

Kubernetes starts with four initial namespaces:

default The default namespace for objects with no other namespace

kube-system The namespace for objects created by the Kubernetes system

kube-public This namespace is created automatically and is readable by all users (including those not authenticated). This namespace is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement.

kube-node-lease This namespace for the lease objects associated with each node which improves the performance of the node heartbeats as the cluster scales.

Most resources are in namespace but low-level resources, such as nodes and persistentVolumes, are not in any namespace.

Create namespaces

apiVersion: v1
kind: Namespace
metadata: 
  name: development
  labels: 
    name: development

Have a definition yml like this and run kubectl apply. Or

kubectl create namespace development

View namespaces

kubectl get namespace

Set namespaces for a request or perm

kubectl run nginx --image=nginx --namespace=<NAMESPACE>
kubectl get pods -n=<NAMESPACE>

kubectl config set-context --current --namespace=<NAMESPACE>
# --current must not be neglected, use --namespace rather than -n 

Search resource under all namespaces

kubectl get pods --all-namespaces
or
kubectl get pods -A

DNS

A service’s DNS entry will be in the following form:

<service-name>.<namespace-name>.svc.<domain-name>

Only need to provide service name when it’s in the current namespace. Otherwise, it is required to provide the fully qualified domain name.

Leave a comment