Its a kubernetes object which partition a single k8 cluster into multiple virtual clusters. By default all the resource created in kubernetes cluster are created in the default namespace.
A pod running in the default namespace will run with unbounded CPU and memory requests/limits. It allows to partition created resources into a logically named group. Each namespace provides following things.
By default kubernetes will have three namespace
$ kubectl get ns
NAME STATUS AGE
default Active 39h
kube-public Active 39h
kube-system Active 39h
default : All Pods that we manually create will go to this namespace (There are ways to change it , but for now that is what it is).
kube-public : All common workloads can be assigned to this namespace . Most of the time no-one use it.
kube-system : Kubernetes specific Pods will be running on this namespace
How to list all the pods in a specific namespace?
$ kubectl get pods --namespace=NAMESPACE_NAME
$ kubectl get all -n kube-system
$ kubectl create ns mydemonamespace
$ kubectl get ns
Create a yaml file with below content.
apiVersion: v1
kind: Namespace
metadata:
name: mydemonamespace-new
$ kubectl create -f yourfilename.yaml
Now check you see the nmaespace you just created.
$ kubectl get ns
Lets create a nginx pod with below content.
apiVersion: v1
kind: Pod
metadata:
name: webserver
labels:
app: nginx
spec:
containers:
- name: webserver
image: nginx:1.9.1
ports:
- containerPort: 80
$ kubectl create -f mywebserver.yaml -n mydemonamespace-new
$ kubectl get pods -n mydemonamespace-new
$ kubectl delete ns mydemonamespace-new
I. Create a multi container pod with name my-multi-pod-demo with below image
II. Create a namespace with $YOURNAME-namespace in a declarative way. Create a pod with a name webserver using nginx image inside this namespace you just created.