Creating a Namespace

For creating a Namespace, following are the steps:

  1. After deciding on our desired name for Namespace, let's create it with a configuration file:
$ cat my-first-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace

// create the resource by subcommand "create"
$ kubectl create -f my-first-namespace.yaml
namespace "my-namespace" created
// list the namespaces again
$ kubectl get ns
NAME STATUS AGE
default Active 16d
kube-public Active 16d
kube-system Active 16d
my-namespace Active 6s
  1. You can now see that we have an additional namespace called my-namespace. Next, let's run a Kubernetes Deployment in this new Namespace:
// run a Deployment with a flag specifying Namespace
$ kubectl run my-nginx --image=nginx --namespace=my-namespace
deployment.apps "my-nginx" created
  1. While trying to check the newly created resource, we cannot easily find them as usual:
$ kubectl get deployment
No resources found.
  1. Instead, the Deployment is shown with a flag related to the Namespace:
// list any Deployment in all Namespaces
$ kubectl get deployment --all-namespaces
NAMESPACE NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
kube-system calico-kube-controllers 1 1 1 1 16d
kube-system calico-policy-controller 0 0 0 0 16d
kube-system kube-dns 1 1 1 1 16d
my-namespace my-nginx 1 1 1 1 1m

// get Deployments from my-namespace
$ kubectl get deployment --namespace=my-namespace
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
my-nginx 1 1 1 1 1m

Now you can find the resource that was just created.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.88.157