Skip to content

Projects/Namespaces

Namespaces are intended for use in environments with many users spread across multiple teams, or projects.

Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces.

Namespaces are a way to divide cluster resources between multiple users (via resource quota).

It is not necessary to use multiple namespaces just to separate slightly different resources, such as different versions of the same software: use labels to distinguish resources within the same namespace. In practice namespaces are used to deploy different versions based on stages of the CICD pipeline (dev, test, stage, prod)

Resources

References

Namespace YAML
apiVersion: v1
kind: Namespace
metadata:
  name: dev
Pod YAML specifiying Namespace
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  namespace: dev
spec:
  containers:
    - name: myapp-container
      image: busybox
      command: ["sh", "-c", "echo Hello Kubernetes! && sleep 3600"]
Getting all namespaces/projects
oc projects
Create a new Project
oc new-project dev
Viewing Current Project
oc project
Setting Namespace in Context
oc project dev
Viewing Project Status
oc status
Getting all namespaces
kubectl get namespaces
Create a new namespace called bar
kubectl create ns dev
Setting Namespace in Context
kubectl config set-context --current --namespace=dev