1
00:00:00,180 --> 00:00:03,390
Hello and welcome to this lecture. In this lecture

2
00:00:03,390 --> 00:00:06,410
we will talk about nodes selectors in Kubernetes.

3
00:00:06,420 --> 00:00:09,080
Let us start with a simple example.

4
00:00:09,450 --> 00:00:16,260
You have a three node cluster of which two are smaller nodes with lower hardware resources and one of

5
00:00:16,260 --> 00:00:23,600
them is a larger node configured with higher resources you have different kinds of workloads running

6
00:00:23,600 --> 00:00:24,820
in your cluster.

7
00:00:25,010 --> 00:00:31,490
You would like to dedicate the data processing workloads that require higher horsepower to the larger

8
00:00:31,490 --> 00:00:39,460
node as that is the only node that will not run out of resources in case the job demands extra resources.

9
00:00:39,470 --> 00:00:45,340
However, in the current default setup, any pods can go to any nodes.

10
00:00:45,380 --> 00: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

11
00:00:53,960 --> 00:00:59,830
we can set a limitation on the pods so that they only run on particular nodes.

12
00:00:59,990 --> 00:01:02,050
There are two ways to do this.

13
00:01:02,060 --> 00:01:06,750
The first is using Node selectors which is the simple and easier method.

14
00:01:06,800 --> 00:01:13,700
For this we look at the pod definition file we created earlier this file has a simple definition to create

15
00:01:13,700 --> 00:01:20,360
a pod with a data processing image to limit this pod to run on the larger node

16
00:01:20,570 --> 00:01:27,500
We add a new property called Node selector to the spec section and specify the size as large.

17
00:01:27,890 --> 00:01:28,670
But wait a minute.

18
00:01:28,760 --> 00:01:36,050
Where did the size large come from and how does Kubernetes know which is the large node. The key value

19
00:01:36,050 --> 00:01:44,240
pair of size and large are in fact labels assigned to the nodes the scheduler uses these labels to match

20
00:01:44,330 --> 00:01:51,230
and identify the right note to place the pods on labels and selectors are a topic we have seen many

21
00:01:51,230 --> 00:01:58,010
times throughout this Kubernetes course such as with services replica sets and deployments to use

22
00:01:58,010 --> 00:02:00,540
labels in a known selector like this.

23
00:02:00,620 --> 00:02:05,440
You must have first labelled your nodes prior to creating this pod.

24
00:02:06,450 --> 00:02:11,620
So let us go back and see how we can label the nodes to label a node.

25
00:02:11,670 --> 00:02:18,330
Use the command Kube control label nodes followed by the name of the node and the label in a key value

26
00:02:18,330 --> 00:02:19,740
pair format.

27
00:02:19,740 --> 00:02:27,060
In this case it would be Kube control label nodes Node 1 followed by the label in a key value format

28
00:02:27,150 --> 00:02:30,030
such as size equals large.

29
00:02:30,030 --> 00:02:36,690
Now that we have labeled the node we can get back to creating the pod this time with the node selector

30
00:02:36,720 --> 00:02:39,180
set to a size of large.

31
00:02:39,180 --> 00:02:47,970
When the pod is now created it is placed on Node 1 as desired not selectors served our purpose but it

32
00:02:47,970 --> 00:02:49,430
has limitations.

33
00:02:49,440 --> 00:02:53,470
We used a single label and selector to achieve our goal here.

34
00:02:53,550 --> 00:02:56,950
But what if our requirement is much more complex.

35
00:02:57,000 --> 00:03:04,080
For example, we would like to say something like place the pod on a large or medium node or something

36
00:03:04,080 --> 00:03:08,240
like place the pod on any nodes that are not small.

37
00:03:08,430 --> 00:03:16,110
You cannot achieve this using Node selectors for this node affinity and anti affinity features were

38
00:03:16,110 --> 00:03:19,020
introduced and we will look at that next.
