WEBVTT

00:00.180 --> 00:03.390
Hello and welcome to this lecture. In this lecture

00:03.390 --> 00:06.410
we will talk about nodes selectors in Kubernetes.

00:06.420 --> 00:09.080
Let us start with a simple example.

00:09.450 --> 00:16.260
You have a three node cluster of which two are smaller nodes with lower hardware resources and one of

00:16.260 --> 00:23.600
them is a larger node configured with higher resources you have different kinds of workloads running

00:23.600 --> 00:24.820
in your cluster.

00:25.010 --> 00:31.490
You would like to dedicate the data processing workloads that require higher horsepower to the larger

00:31.490 --> 00:39.460
node as that is the only node that will not run out of resources in case the job demands extra resources.

00:39.470 --> 00:45.340
However, in the current default setup, any pods can go to any nodes.

00:45.380 --> 00:53.940
So Pod C in this case may very well end up on nodes two or three which is not desired. To solve this

00:53.960 --> 00:59.830
we can set a limitation on the pods so that they only run on particular nodes.

00:59.990 --> 01:02.050
There are two ways to do this.

01:02.060 --> 01:06.750
The first is using Node selectors which is the simple and easier method.

01:06.800 --> 01:13.700
For this we look at the pod definition file we created earlier this file has a simple definition to create

01:13.700 --> 01:20.360
a pod with a data processing image to limit this pod to run on the larger node

01:20.570 --> 01:27.500
We add a new property called Node selector to the spec section and specify the size as large.

01:27.890 --> 01:28.670
But wait a minute.

01:28.760 --> 01:36.050
Where did the size large come from and how does Kubernetes know which is the large node. The key value

01:36.050 --> 01:44.240
pair of size and large are in fact labels assigned to the nodes the scheduler uses these labels to match

01:44.330 --> 01:51.230
and identify the right note to place the pods on labels and selectors are a topic we have seen many

01:51.230 --> 01:58.010
times throughout this Kubernetes course such as with services replica sets and deployments to use

01:58.010 --> 02:00.540
labels in a known selector like this.

02:00.620 --> 02:05.440
You must have first labelled your nodes prior to creating this pod.

02:06.450 --> 02:11.620
So let us go back and see how we can label the nodes to label a node.

02:11.670 --> 02:18.330
Use the command Kube control label nodes followed by the name of the node and the label in a key value

02:18.330 --> 02:19.740
pair format.

02:19.740 --> 02:27.060
In this case it would be Kube control label nodes Node 1 followed by the label in a key value format

02:27.150 --> 02:30.030
such as size equals large.

02:30.030 --> 02:36.690
Now that we have labeled the node we can get back to creating the pod this time with the node selector

02:36.720 --> 02:39.180
set to a size of large.

02:39.180 --> 02:47.970
When the pod is now created it is placed on Node 1 as desired not selectors served our purpose but it

02:47.970 --> 02:49.430
has limitations.

02:49.440 --> 02:53.470
We used a single label and selector to achieve our goal here.

02:53.550 --> 02:56.950
But what if our requirement is much more complex.

02:57.000 --> 03:04.080
For example, we would like to say something like place the pod on a large or medium node or something

03:04.080 --> 03:08.240
like place the pod on any nodes that are not small.

03:08.430 --> 03:16.110
You cannot achieve this using Node selectors for this node affinity and anti affinity features were

03:16.110 --> 03:19.020
introduced and we will look at that next.

