Kubernetes Namespaces
Kubernetes Namespaces
Kubernetes Namespaces
What is namespace?
Kubernetes supports multiple virtual clusters backed by the same physical cluster. These
virtual clusters are called namespaces.
Namespaces are intended for use in environments with many users spread across multiple
teams, or projects.
For clusters with a few to tens of users, you should not need to create or think about
namespaces at all.
Namespaces provide a scope for names. Names of resources need to be unique within a
namespace, but not across namespaces.
Using a Kubernetes namespace could isolate namespaces for different environments (dev,
staging, preprod, prod) in the same cluster.
Viewing namespaces
$ kubectl get namespace
NAME STATUS AGE
default Active 1d
kube-system Active 1d
kube-public Active 1d
default The default namespace resource you create are located here.
The name of a namespace must be a DNS label and follow the following rules:
At most 63 characters
Matching regex [a-z0-9]([-a-z0-9]*[a-z0-9])
Creating Namespace
Type1 :
Create namespace trough command line
Type2 :
Create namespace trough yaml file
$vi newNamespace.yml
apiVersion: v1
kind: Namespace
metadata:
name: new-namespace
This deployment will create one pod , replicaset and deployment object
Type 2:
You can specify the namespace in yaml file
$vi mytutum.yml
apiVersion: v1
kind: Pod
metadata:
name: mytutum
labels:
zone: prod
version: v1
namespace: test
spec:
containers:
- name: mytutumapp
image: tutum/hello-world
ports:
- containerPort: 80
$ kubectl get pods --namespace=test
Deleting a namespace
1. Using kubectl delete could delete the resources including the namespace.
Deleting a namespace will erase all the resources under that namespace:
It will try to create an tutum replication controller and replica pod in the
current namespace we just deleted. Kubernetes will throw out an error if the
namespace is not found.