Site icon i2tutorials

Kubernetes – Namespace

Kubernetes – Namespace

 

Adding a namespace to a resource name helps prevent name collisions when multiple teams are using the same cluster. It serves as a virtual wall between clusters.

Functionality of Namespace

A Namespace in Kubernetes has the following features:

Create a Namespace

Create a namespace with this command.

apiVersion: v1
kind: Namespce
metadata
   name: elk

Control the Namespace

Namespaces are controlled with the following command.

$ kubectl create –f namespace.yml ---------> 1
$ kubectl get namespace -----------------> 2
$ kubectl get namespace <Namespace name> ------->3
$ kubectl describe namespace <Namespace name> ---->4
$ kubectl delete namespace <Namespace name>

As shown in the code above,

Service Namespace – Example

The following is an example of a service file that uses namespaces.

apiVersion: v1
kind: Service
metadata:
   name: elasticsearch
   namespace: elk
   labels:
      component: elasticsearch
spec:
   type: LoadBalancer
   selector:
      component: elasticsearch
   ports:
   - name: http
      port: 9200
      protocol: TCP
   - name: transport
      port: 9300
      protocol: TCP

We’re using the same namespace under service metadata with the name elk.

 

Exit mobile version