• Home
  • DevOps
  • Namespace, Labels and Selectors in Kubernetes

Namespace, Labels and Selectors in Kubernetes

Last updated on May 27 2022
Sankalp Rai

Table of Contents

Namespace, Labels and Selectors in Kubernetes

Kubernetes – Labels & Selectors

Labels

Labels are key-value pairs which are attached to pods, replication controller and services. They are used as identifying attributes for objects such as pods and replication controller. They can be added to an object at creation time and can be added or modified at the run time.

Selectors

Labels do not provide uniqueness. In general, we can say many objects can carry the equivalent labels. Labels selector are core grouping primitive in Kubernetes. They are used by the users to select a group of objects.
Kubernetes API currently supports two types of selectors −
• Equality-based selectors
• Group-based selectors
Equality-based Selectors
They allow filtering by key and value. Matching objects should satisfy all the specified labels.
Group-based Selectors
Group-based selectors allow filtering of keys according to a group of values.
apiVersion: v1
kind: Service
metadata:
name: sp-neo4j-standalone
spec:
ports:
– port: 7474
name: neo4j
type: NodePort
selector:
app: salesplatform ———> 1
component: neo4j ———–> 2
In the above code, we are using the label selector as app: salesplatform and component as component: neo4j.
Once we run the file using the kubectl command, it will create a service with the name sp-neo4j-standalone which will communicate on port 7474. The ype is NodePort with the new label selector as app: salesplatform and component: neo4j.

Kubernetes – Namespace

Namespace provides an additional qualification to a resource name. This is helpful when multiple teams are using the equivalent cluster and there is a potential of name collision. It can be as a virtual wall between multiple clusters.

Functionality of Namespace

Subsequent are some of the important functionalities of a Namespace in Kubernetes −
• Namespaces help pod-to-pod communication using the equivalent namespace.
• Namespaces are virtual clusters that can sit on top of the equivalent physical cluster.
• They provide logical separation between the teams and their environments.

Create a Namespace

The subsequent command is used to create a namespace.
apiVersion: v1
kind: Namespce
metadata
name: elk

Control the Namespace

The subsequent command is used to control the namespace.
$ 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>
In the above code,
• We are using the command to create a namespace.
• This will list all the available namespace.
• This will get a particular namespace whose name is specified in the command.
• This will describe the complete details about the service.
• This will delete a particular namespace present in the cluster.

Using Namespace in Service – Example

Subsequent is an example of a sample file for using namespace in service.
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
In the above code, we are using the equivalent namespace under service metadata with the name of elk.
So, this brings us to the end of blog. This Tecklearn ‘Namespace, Labels and Selectors in Kubernetes’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Kubernetes and build a career in DevOps domain, then check out our interactive, Continuous Orchestration using Kubernetes Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Continuous Orchestration using Kubernetes

Continuous Orchestration using Kubernetes Training

About the Course

Tecklearn has specially designed this Continuous Orchestration using Kubernetes Training Course to advance your skills for a successful career in this domain. Kubernetes training helps you master the container orchestration tool. As part of the training, you will learn detailed Kubernetes, architecture of Kubernetes, what are Kubernetes Pods, node, how to deploy Kubernetes, creating a Kubernetes cluster, what are the various services available and how Kubernetes makes container orchestration simple. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Kubernetes.

Why Should you take Continuous Orchestration using Kubernetes Training?

• The average salary for people who possess Kubernetes as a skill is $117,000. – PayScale.com
• Apple, Capital One, AT&T, Oracle, Raytheon & many other MNC’s worldwide use Kubernetes across industries.
• The Kubernetes orchestration engine powers some of the biggest and most complex deployments in the world.

What you will Learn in this Course?

Introduction to DevOps
• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation
Continuous Orchestration using Kubernetes
• Containers and Container Orchestration
• Introduction to Kubernetes
• Docker Swarm vs Kubernetes
• Kubernetes Architecture
• Deploying Kubernetes using Kubeadms
• Alternate ways of deploying Kubernetes
• Understanding YAML
• Creating a Deployment in Kubernetes using YAML
• Creating a Service in Kubernetes
• Installing Kubernetes Dashboard
• Deploying an App using Dashboard
• Using Rolling Updates in Kubernetes

0 responses on "Namespace, Labels and Selectors in Kubernetes"

Leave a Message

Your email address will not be published. Required fields are marked *