xxxxxxxxxx
V1Namespace ns = new V1Namespace().metadata(new V1ObjectMeta().name("new-namespace"));
CoreV1Api api = new CoreV1Api();
V1Namespace createdNamespace = api.createNamespace(ns, null, null, null);
xxxxxxxxxx
demo-namespace.yml
apiVersion: v1
kind: Namespace
metadata:
name: demo
labels:
env: dev
$ kubectl create -f demo-namespace.yml
$ kubectl get namespaces -o=json
$ kubectl get namespaces demo -o=json/yaml/name
xxxxxxxxxx
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "production",
"labels": {
"name": "production"
}
}
}
xxxxxxxxxx
Namespaces are a way to organize clusters into virtual sub-clusters — they can be helpful when different teams or projects share a Kubernetes cluster. Any number of namespaces are supported within a cluster, each logically separated from others but with the ability to communicate with each other.
xxxxxxxxxx
env:
- name: "KUBERNETES_NAMESPACE"
valueFrom:
fieldRef:
fieldPath: "metadata.namespace"