# Kubernetes - Namespaces
###### tags: `Kubernetes`
## Foreword
> When the objects of cluster and people using Kubernetes cluster are increasing, we can use the Namespaces to manage our project.
>
## Namespaces
### Definition
> Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces. Namespaces are a way to divide cluster resources between multiple user.
>
### Features
* In the same kubernetes cluster all of namespaces are unique.
* When we delete the namespaces, the object of namespace will be deleted in the same time.
* We can use the Resource Quotas to limit the resource of the object in that Namespace.
## Practice
> We can use `kubectl get namespaces` to see the all namespaces on the kubernetes cluster.
>

* default
When you create the object, you don’t set the namespace the namespaces of object will be default.
* kube-system
The namespace for objects created by the Kubernetes system.
* kube-public
This namespace is created automatically and is readable by all users.
> We can use `kubectl create namespace <namespace_name>` to create a new namespace.
>
> We also can use `kubectl delete namespaces <namespace_name>` to delete namespaces.
>
### Recourse Quotas
> Use the follow yaml file to create a Namespace and Resource Quotas.
>
````yaml=1
apiVersion: v1
kind: Namespace
metadata:
name: hello-space
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quotas
namespace: hello-space
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 10Gi
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: object-quotas
namespace: hello-space
spec:
hard:
services: "2"
services.loadbalancers: "1"
secrets: "1"
configmaps: "1"
replicationcontrollers: "10"
````
> In this yaml we create a “hellospace” namespace.
>
* compute-quotas
Limit the resource of cpu and memory.
* object-quotas
Limit the namespace can only has two services, and one loadbalancer, secret, and configmap.
## Reference
> https://ithelp.ithome.com.tw/articles/10197186
>
> https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
>
>https://kubernetes.io/docs/concepts/policy/resource-quotas/