1
00:00:02,040 --> 00:00:04,030
So where's this error coming from?

2
00:00:04,030 --> 00:00:06,820
What's this missing selector thing?

3
00:00:06,820 --> 00:00:11,800
Well, we fix it by going to the specification

4
00:00:11,800 --> 00:00:13,690
of our deployment

5
00:00:13,690 --> 00:00:16,360
so not the specification of the pod

6
00:00:16,360 --> 00:00:18,700
but the specification of the deployment.

7
00:00:18,700 --> 00:00:21,770
And besides specifying the number of replicas

8
00:00:21,770 --> 00:00:23,930
and our pods template here,

9
00:00:23,930 --> 00:00:28,010
we also must add a selector key here.

10
00:00:28,010 --> 00:00:30,996
And on this selector key nested below it

11
00:00:30,996 --> 00:00:34,750
we can add a match labels key,

12
00:00:34,750 --> 00:00:35,961
and then nested below that

13
00:00:35,961 --> 00:00:40,770
a key/value pair of the pod labels

14
00:00:40,770 --> 00:00:43,053
we wanna match with this deployment.

15
00:00:44,120 --> 00:00:45,520
Okay, that sounds very triptych.

16
00:00:45,520 --> 00:00:47,270
What does this mean?

17
00:00:47,270 --> 00:00:48,103
Well,

18
00:00:48,103 --> 00:00:50,940
we got a template here for this deployment

19
00:00:50,940 --> 00:00:52,840
and therefore it should be obvious

20
00:00:52,840 --> 00:00:56,080
which pods are created by this deployment.

21
00:00:56,080 --> 00:00:57,450
And it kind of is.

22
00:00:57,450 --> 00:00:59,973
The pod defined in this template will be created

23
00:00:59,973 --> 00:01:02,443
when this deployment is applied.

24
00:01:03,630 --> 00:01:08,020
But deployments are dynamic objects or dynamic things

25
00:01:08,020 --> 00:01:09,610
in the Kubernetes world.

26
00:01:09,610 --> 00:01:10,443
For example,

27
00:01:10,443 --> 00:01:12,990
if you scale up the number of pods

28
00:01:12,990 --> 00:01:15,650
after a deployment has been created,

29
00:01:15,650 --> 00:01:17,959
these new pods which are created

30
00:01:17,959 --> 00:01:20,810
will still automatically be managed

31
00:01:20,810 --> 00:01:23,133
by the already existing deployment.

32
00:01:24,140 --> 00:01:28,450
So a deployment continuously watches all the pods

33
00:01:28,450 --> 00:01:29,800
which are out there

34
00:01:29,800 --> 00:01:34,140
and sees if there are any pods it should control.

35
00:01:34,140 --> 00:01:37,550
And it selects the to be controlled pods

36
00:01:37,550 --> 00:01:39,690
with a so-called selector.

37
00:01:39,690 --> 00:01:41,320
And you will see selectors

38
00:01:41,320 --> 00:01:45,020
on pretty much all resources Kubernetes works with.

39
00:01:45,020 --> 00:01:48,040
For example, Azure Services.

40
00:01:48,040 --> 00:01:50,410
Now there are different types of selectors

41
00:01:50,410 --> 00:01:51,940
here for a deployment

42
00:01:51,940 --> 00:01:55,190
we can use two different kinds of selecting.

43
00:01:55,190 --> 00:01:59,690
We can match labels and we can match expressions.

44
00:01:59,690 --> 00:02:02,930
Now expressions are more complex selectors

45
00:02:02,930 --> 00:02:05,430
so we'll not have a look at them right now

46
00:02:05,430 --> 00:02:07,900
instead we'll match labels.

47
00:02:07,900 --> 00:02:11,910
And then nested below that you simply have key/value pairs

48
00:02:11,910 --> 00:02:16,110
of labels on the pods which should be controlled

49
00:02:16,110 --> 00:02:17,643
by that deployment.

50
00:02:18,560 --> 00:02:21,720
So in this case, we are trading these pots

51
00:02:21,720 --> 00:02:23,960
which have this label on it.

52
00:02:23,960 --> 00:02:24,793
And by the way,

53
00:02:24,793 --> 00:02:27,580
they could have multiple labels.

54
00:02:27,580 --> 00:02:30,940
Which as mentioned before are totally up to you.

55
00:02:30,940 --> 00:02:34,163
Both the key and the value are up to you.

56
00:02:35,350 --> 00:02:38,160
But you can have one or more labels

57
00:02:38,160 --> 00:02:41,160
on a given object in this case on a pod.

58
00:02:41,160 --> 00:02:44,590
And then you can connect that to another object

59
00:02:44,590 --> 00:02:45,423
in this case,

60
00:02:45,423 --> 00:02:48,320
to the deployment with a so-called selector

61
00:02:48,320 --> 00:02:51,240
so that this deployment knows which pods

62
00:02:51,240 --> 00:02:52,991
which are out there running in the cluster

63
00:02:52,991 --> 00:02:55,073
should be controlled by it.

64
00:02:55,950 --> 00:02:59,600
And you then simply add the key/value pairs of the pods

65
00:02:59,600 --> 00:03:02,850
that should be controlled below match labels here.

66
00:03:02,850 --> 00:03:05,003
So for example like this,

67
00:03:07,020 --> 00:03:10,400
now I would tell this deployment

68
00:03:10,400 --> 00:03:13,930
that all the pods which have a label of app

69
00:03:13,930 --> 00:03:16,040
with a value of second app,

70
00:03:16,040 --> 00:03:19,060
and which have a label with a name of tier

71
00:03:19,060 --> 00:03:20,720
with a value of backend,

72
00:03:20,720 --> 00:03:23,395
should be controlled by this deployment.

73
00:03:23,395 --> 00:03:26,610
Other pods which only have app,

74
00:03:26,610 --> 00:03:27,490
second app,

75
00:03:27,490 --> 00:03:29,140
but not this tier

76
00:03:29,140 --> 00:03:31,350
or which have a different app label

77
00:03:31,350 --> 00:03:34,840
or which don't have the app and tier label at all

78
00:03:34,840 --> 00:03:38,640
will not be controlled by this deployment.

79
00:03:38,640 --> 00:03:40,340
I hope this makes sense.

80
00:03:40,340 --> 00:03:41,640
It tells the deployment

81
00:03:41,640 --> 00:03:44,323
which pods belong to it so to say.

82
00:03:45,290 --> 00:03:49,360
And we'll see this again, when we later work on a service.

83
00:03:49,360 --> 00:03:52,280
So for the moment let's save this updated file

84
00:03:52,280 --> 00:03:55,173
and let's now try applying this file again.

85
00:03:56,080 --> 00:03:57,500
And this now looks better.

86
00:03:57,500 --> 00:03:58,333
Now, you'll see

87
00:03:58,333 --> 00:04:00,140
this deployment was created.

88
00:04:00,140 --> 00:04:00,973
And therefore,

89
00:04:00,973 --> 00:04:01,806
if you run,

90
00:04:01,806 --> 00:04:03,550
get deployments here,

91
00:04:03,550 --> 00:04:06,643
you see that deployment up and running.

92
00:04:07,980 --> 00:04:11,270
And of course, if we now call get pods,

93
00:04:11,270 --> 00:04:13,400
we also see this up and running,

94
00:04:13,400 --> 00:04:15,740
but now we didn't have to enter a command

95
00:04:15,740 --> 00:04:17,000
in the command line

96
00:04:17,000 --> 00:04:19,290
except for the apply command of course.

97
00:04:19,290 --> 00:04:20,123
But instead,

98
00:04:20,123 --> 00:04:24,910
all our configuration is encoded here in this conflict file.

99
00:04:26,850 --> 00:04:28,950
Now at the moment we can't visit the app

100
00:04:28,950 --> 00:04:30,740
because a services missing

101
00:04:30,740 --> 00:04:32,930
but this is a huge step forward

102
00:04:32,930 --> 00:04:36,950
since we now know about this declarative approach.

103
00:04:36,950 --> 00:04:41,093
Let's now see how we can also declare a service resource.

