Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

In this Demo:

-------------
We will create the new Namespace and deploy sample Pod in that new Namespace.

***********************************************************************************
****************

1. Creating NameSpace:
~~~~~~~~~~~~~~~~~~~~~~

1a). Using YAML:


----------------
# dev-ns.yaml
apiVersion: v1
kind: Namespace
metadata:
name: dev

kubectl apply -f dev-ns.yaml

1b). Using Imepratively:


-------------------------
kubectl create namespace test

***********************************************************************************
****************

2. Displaying Namespace
~~~~~~~~~~~~~~~~~~~~~~~
kubectl get ns [NAMESPACE-NAME]
kubectl get ns [NAMESPACE-NAME] -o yaml
kubectl get pods -n [NAMESPACE-NAME]

kubectl describe ns [NAMESPACE-NAME]

***********************************************************************************
****************

3. Creating Pod Object in Specific NameSpace:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

kubectl run nginx --image=nginx --namespace=dev

Validate:
----------
kubectl get pods
kubectl get pods -n dev

***********************************************************************************
****************

4. Displaying Objects in All Namespace:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kubectl get pods -A
or
kubectl get [object-name] --all-namespaces

***********************************************************************************
****************

5. Setting the namespace preference:


------------------------------------

Syntax:
kubectl config set-context --current --namespace=<insert-namespace-name-here>

-----------

kubectl config view --minify | grep namespace:


kubectl get pods

kubectl config set-context --current --namespace=test


kubectl config view --minify | grep namespace:
kubectl run redis --image=redis
kubectl get pods

kubectl config set-context --current --namespace=default


kubectl config view --minify | grep namespace:
kubectl run httpd --image=httpd

***********************************************************************************
****************

6. Deleting Namespaces
~~~~~~~~~~~~~~~~~~~~~~
kubectl delete pods nginx -n dev
kubectl delete pods redis -n test
kubectl delete pods httpd
kubectl get pods -A

kubectl get ns
kubectl delete ns dev
kubectl delete ns test
kubectl get ns
kubectl get pods

***********************************************************************************
****************

You might also like