1
00:00:00,000 --> 00:00:11,333
Hi, Let us have a quick understanding on selector operator. In many of the objects

2
00:00:11,333 --> 00:00:16,866
like deployments, replica sets or even services we will be using the selector to

3
00:00:16,866 --> 00:00:21,132
select any specific object using the labels and there are different

4
00:00:21,133 --> 00:00:25,366
combinations we can provide to select the objects. For understanding purpose

5
00:00:25,366 --> 00:00:31,099
I'm going to deploy an application and use the selector to select the pods to

6
00:00:31,100 --> 00:00:36,000
understand how different ways we can use the selectors. Let me go ahead and

7
00:00:36,000 --> 00:00:43,400
use a yaml file that's available as a part of kubernetes samples. Here there is a

8
00:00:43,400 --> 00:00:49,300
yaml file all in one guest book where it is going to deploy 3 different services and

9
00:00:49,300 --> 00:00:54,200
deployments, say for example I am going to have a service called redis master

10
00:00:54,200 --> 00:01:00,000
that's going to have different labels and a deployment for redis master at the

11
00:01:00,000 --> 00:01:04,933
same way I'm going to have another service for redis-slave and deployment

12
00:01:04,933 --> 00:01:09,466
for redis slave and deployment for frontend, it's going to have different

13
00:01:09,466 --> 00:01:16,032
labels, I'm going to use this specific yaml file and get this deployed within the

14
00:01:16,033 --> 00:01:23,199
kubernetes. Let me use the command kubectl apply, then the file path you can

15
00:01:23,200 --> 00:01:28,000
read directly from the github user content and automatically it's going to

16
00:01:28,000 --> 00:01:34,466
create the service and deployment. Now let me go ahead and get the deployments I can

17
00:01:34,466 --> 00:01:43,166
say kubectl get deployment and get services, so I should have the details

18
00:01:43,166 --> 00:01:48,566
about the service and the deployments, all the deployments are in readystate the

19
00:01:48,566 --> 00:01:55,199
required capacity it got deployed. Now I can use the get pods option and use the

20
00:01:55,200 --> 00:02:01,666
selector. Now I am going to get all the pods kubectl get pods and I want the

21
00:02:01,666 --> 00:02:07,299
labels to get displayed for each and every pods, so I'll use the option show labels. So

22
00:02:07,300 --> 00:02:11,500
that's going to have the labels attached to those pods like

23
00:02:11,500 --> 00:02:18,466
app guest book, app nginx, app redis, so all the labels will get displayed. Now

24
00:02:18,466 --> 00:02:25,099
I am going to get the pods with what are all the labels attached to what pods. So

25
00:02:25,100 --> 00:02:32,100
I'm going to list the pods with the label app tier and role, for few minutes let me

26
00:02:32,100 --> 00:02:37,300
reduce the font so that I will be getting each and every item in a single row. So

27
00:02:37,300 --> 00:02:42,000
the app what is the value that's used, that'll get listed over here and for tier

28
00:02:42,000 --> 00:02:47,400
what is the role that is used and for role what is the value that was used. Now let

29
00:02:47,400 --> 00:02:52,466
me go ahead and verify the yaml file, here I do have different labels like app

30
00:02:52,466 --> 00:02:58,432
tier, role and this is what we are listing what value was assigned to that specific

31
00:02:58,433 --> 00:03:06,266
pod and what is the label. So I am trying to list the value for the label app, label tier

32
00:03:06,266 --> 00:03:12,532
and label role. So this is another way of listing the pods now I can go ahead and

33
00:03:12,533 --> 00:03:19,599
use the selector where app is redis. So I'm selecting all the pods where the app is

34
00:03:19,600 --> 00:03:25,866
redis, so it's going to get all the pods where app is redis, so I do have 3 pods

35
00:03:25,866 --> 00:03:32,599
with the label app is redis. Now I can go ahead and have another combination

36
00:03:32,600 --> 00:03:39,800
where app is redis and role is slave, so I do have 2 pods with app is redis and role

37
00:03:39,800 --> 00:03:48,500
as slaves and I can go for the collections as well, where role in master or slave. So I'll be

38
00:03:48,500 --> 00:03:53,133
having both the combinations and all the pods meeting this specific condition will

39
00:03:53,133 --> 00:03:58,566
get selected. I can even go for the negative conditions where it doesn't have

40
00:03:58,566 --> 00:04:05,999
the app label. so here I do have all the pods where the app label is set, now I am

41
00:04:06,000 --> 00:04:13,333
going to get all the pods where app label is not set. So I am using the selector not

42
00:04:13,333 --> 00:04:17,499
that is exclamatory mark and then app, so there is no resources

43
00:04:17,500 --> 00:04:22,233
available in case if there were any resources that will get selected. Maybe

44
00:04:22,233 --> 00:04:28,033
I can go ahead and create a sample pod and check whether that is getting

45
00:04:28,033 --> 00:04:33,666
selected or not. So I am going to run a pod with a name nginx run with a image

46
00:04:33,666 --> 00:04:38,599
nginx. Now let me go ahead and use the exclamatory mark where it doesn't have

47
00:04:38,600 --> 00:04:44,866
a label app, of course the new pod that we created we did not set the label app

48
00:04:44,866 --> 00:04:50,432
so it's getting selected for this specific condition. So the selector we will be using

49
00:04:50,433 --> 00:04:55,966
it extensively to pick the pod that we wanted to act on as there will be

50
00:04:55,966 --> 00:04:59,332
hundreds and hundreds of pods and other objects running within the

51
00:04:59,333 --> 00:05:05,266
kubernetes cluster, whenever there is a need to pick a group of pods I will be

52
00:05:05,266 --> 00:05:11,666
using this particular label to pick the pods and take the actions like deploying

53
00:05:11,666 --> 00:05:17,099
them or terminating them or in case if I wanted to scale up scale down n number

54
00:05:17,100 --> 00:05:23,233
of actions I can do. So basically the labels will be used to select where the

55
00:05:23,233 --> 00:05:27,999
pod should run, how the pod should run, what action to be taken against what set

56
00:05:28,000 --> 00:05:33,100
of pods, in lot more places we will be using it. So this is the quick summary on

57
00:05:33,100 --> 00:05:37,000
how we can use the selectors what are all different types of combinations and

58
00:05:37,000 --> 00:05:39,833
of course lot more combinations can be used these are all the

59
00:05:39,833 --> 00:05:45,233
frequently used to combinations while using the label selector.

