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 often used to separate teams, applications, or stages of the CI/CD pipeline (dev, test, stage, prod).

Projects in OpenShift

An OpenShift Project is a Kubernetes namespace with extra metadata (display name, description) and default access control. When you run oc new-project, OpenShift creates the namespace and makes you its admin, even if you aren't allowed to create namespaces directly. Use oc new-project rather than oc create namespace on OpenShift.

Resources

References

Namespace YAML
apiVersion: v1
kind: Namespace
metadata:
  name: dev
Pod YAML specifying 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 dev
kubectl create ns dev
Setting Namespace in Context
kubectl config set-context --current --namespace=dev