how to use kubernetes namespaces to create deployment code example

Example 1: kubernetes create namespace

# Create NS
kubectl create namespace my-namespace
# Select NS
kubectl config set-context --current --namespace=my-namespace
# Check current NS
kubectl config view | grep namespace

Example 2: kubernetes java client create namespace

V1Namespace ns = new V1Namespace().metadata(new V1ObjectMeta().name("new-namespace"));
CoreV1Api api = new CoreV1Api();
V1Namespace createdNamespace = api.createNamespace(ns, null, null, null);