1
00:00:05,330 --> 00:00:07,470
Hello and welcome to this lecture on Cuba.

2
00:00:07,470 --> 00:00:08,600
It is controllers.

3
00:00:08,600 --> 00:00:10,300
My name is Mom child Mohamed.

4
00:00:10,540 --> 00:00:14,960
In this lecture we will discuss about Cuban it is controllers.

5
00:00:14,960 --> 00:00:17,900
Controllers are the brains behind Cuban interests.

6
00:00:17,900 --> 00:00:23,860
They are the processes that monitor Cuban natives objects and respond accordingly.

7
00:00:23,900 --> 00:00:33,090
In this lecture we will discuss about one controller in particular and that is the replication controller.

8
00:00:33,130 --> 00:00:38,350
So what is a replica and why do we need a replication controller.

9
00:00:38,350 --> 00:00:44,070
Let's go back to our first scenario where we had a single pod running our application.

10
00:00:44,170 --> 00:00:48,270
What if for some reason our application crashes and the pod fails.

11
00:00:48,460 --> 00:00:56,050
Users will no longer be able to access our application to prevent users from losing access to our application.

12
00:00:56,050 --> 00:01:01,380
We would like to have more than one instance or pod running at the same time.

13
00:01:01,450 --> 00:01:06,660
That way if one failed we still have our application running on the other one.

14
00:01:06,820 --> 00:01:13,870
The replication controller helps us run multiple instances of a single pod in the cabinet as cluster

15
00:01:14,350 --> 00:01:22,090
thus providing high availability so does that mean you can't use a replication controller if you plan

16
00:01:22,090 --> 00:01:24,260
to have a single pod.

17
00:01:24,310 --> 00:01:25,120
No.

18
00:01:25,180 --> 00:01:32,590
Even if you have a single pod the replication controller can help by automatically bringing up a new

19
00:01:32,590 --> 00:01:35,240
pod when the existing one fails.

20
00:01:35,500 --> 00:01:42,370
Thus the replication controller ensures that the specified number of parts are running at all times

21
00:01:42,520 --> 00:01:51,060
even if it's just one or 100 another reason we need a replication controller is to create multiple paths

22
00:01:51,120 --> 00:01:53,400
to share the load across them.

23
00:01:53,400 --> 00:02:01,080
For example in this simple scenario we have a single pod serving a set of users when the number of users

24
00:02:01,110 --> 00:02:01,860
increase.

25
00:02:01,860 --> 00:02:09,560
We deploy additional pod to balance the load across the two parts if the demand further increases and

26
00:02:09,560 --> 00:02:16,340
if we were to run out of resources on the first node we could deploy additional pods across the other

27
00:02:16,340 --> 00:02:18,240
nodes in the cluster.

28
00:02:18,320 --> 00:02:24,880
As you can see the replication controller spans across multiple nodes in the cluster.

29
00:02:24,950 --> 00:02:31,910
It helps us balance the load across multiple paths on different nodes as well as scale our application.

30
00:02:32,030 --> 00:02:41,040
When the demand increases it's important to note that there are two similar terms replication controller

31
00:02:41,190 --> 00:02:43,000
and replay cassette.

32
00:02:43,140 --> 00:02:50,550
Both have the same purpose but they're not the same replication controller is the older technology that

33
00:02:50,550 --> 00:02:58,280
is being replaced by replicate set properly has said is the new recommended way to setup replication.

34
00:02:58,350 --> 00:03:05,350
However whatever we discussed in the previous few slides remain applicable to both these technologies.

35
00:03:05,640 --> 00:03:11,050
There are minor differences in the way each works and we will look at that in a bit.

36
00:03:11,190 --> 00:03:18,170
As such we will try to stick to replicable sets in all of our demos and implementations going forward.

37
00:03:19,360 --> 00:03:23,760
Let us now look at how we create a replication controller.

38
00:03:23,770 --> 00:03:30,490
As with the previous lecture we start by creating a replication controller definition file we will name

39
00:03:30,490 --> 00:03:37,120
it our C dash to finish thought Jamil as with any Cuban Interest definition file.

40
00:03:37,130 --> 00:03:47,090
We have four sections the API version kind metadata and spec the API version is specific to what we

41
00:03:47,090 --> 00:03:53,990
are creating in this case replication controller is supported in Coburn it is API version V1.

42
00:03:54,710 --> 00:04:03,740
So we will set it as v1 the kind as we know is a replication controller under a metadata we will add

43
00:04:03,800 --> 00:04:12,500
a name and we will call it my ab dash RC and we will also add a few labels app and type and assign values

44
00:04:12,500 --> 00:04:12,860
to them.

45
00:04:13,820 --> 00:04:19,420
So far it has been very similar to how we created a pod in the previous section.

46
00:04:19,460 --> 00:04:26,510
The next is the most crucial part of the definition file and that is the specification written as spec

47
00:04:27,420 --> 00:04:29,980
for any Cuban it is definition file.

48
00:04:30,030 --> 00:04:34,710
The spec section defines what's inside the object we are creating.

49
00:04:34,710 --> 00:04:43,130
In this case we know that the replication controller creates multiple instances of a part but what part

50
00:04:43,860 --> 00:04:51,330
we create a template section under spec to provide a part template to be used by the replication controller

51
00:04:51,480 --> 00:04:57,440
to create replicas now how do we define the part template.

52
00:04:57,440 --> 00:05:03,250
It's not that hard because we have already done that in the previous exercise.

53
00:05:03,290 --> 00:05:08,430
Remember we created a pod definition file in the previous exercise.

54
00:05:08,540 --> 00:05:16,140
We could reuse the contents of the file to populate the template section move all the contents of the

55
00:05:16,140 --> 00:05:22,680
pod definition file into the template section of the replication controller except for the first few

56
00:05:22,680 --> 00:05:31,060
lines which are API version and kind remember whatever we move must be under the template section meaning

57
00:05:31,060 --> 00:05:35,980
this should be intended to the right and have more spaces before them.

58
00:05:36,040 --> 00:05:44,070
Then the template line itself they should be children of the template section looking at our file.

59
00:05:44,080 --> 00:05:47,890
Now we now have two method metadata sections.

60
00:05:47,890 --> 00:05:57,550
One is for the replication controller and another for the pod and we have two aspects sections one for

61
00:05:57,550 --> 00:06:02,180
each.

62
00:06:02,350 --> 00:06:05,540
We have nested to definition files together.

63
00:06:05,740 --> 00:06:11,750
The replication controller being the parent and the part definition being the child.

64
00:06:11,880 --> 00:06:14,300
Now there is something still missing.

65
00:06:14,300 --> 00:06:20,340
We haven't mentioned how many replicas we need in the replication controller for that.

66
00:06:20,340 --> 00:06:27,330
Add another property to the spec called replicas and input the number of replicas you need under it.

67
00:06:27,380 --> 00:06:34,970
Remember that the template and replicas are direct children of spec sections so they are siblings and

68
00:06:34,970 --> 00:06:42,590
must be on the same vertical line which means having equal number of spaces before them once the file

69
00:06:42,590 --> 00:06:50,720
is ready run the cubes GTL create command and input the file using the dash f parameter the replication

70
00:06:50,720 --> 00:06:57,110
controller is created when the replication controller is created it first creates the part using the

71
00:06:57,110 --> 00:07:00,920
part definition template as many as required which is 3.

72
00:07:00,920 --> 00:07:08,810
In this case to view the list of created replication controllers run the cube CDL get replication controller

73
00:07:08,810 --> 00:07:15,170
command and you will see the replication controller listed we can also see the desired number of friendly

74
00:07:15,180 --> 00:07:20,750
cars or parts the current number of friendly cars and how many of them are ready in the output.

75
00:07:21,110 --> 00:07:26,620
If you would like to see the parts that were created by the replication controller run the cube CDL

76
00:07:26,780 --> 00:07:30,760
get parts command and you will see three parts running.

77
00:07:30,770 --> 00:07:37,580
Note that all of them are starting with the name of the replication controller which is my ab dash RC

78
00:07:37,970 --> 00:07:45,920
indicating that they are all created automatically by the replication controller what we just saw was

79
00:07:45,980 --> 00:07:52,670
the replication controller let us now look at replica set it is very similar to replication controller

80
00:07:53,120 --> 00:08:00,950
as usual first we have API version kind metadata and spec the API version though is a bit different

81
00:08:01,190 --> 00:08:07,550
it is apps slash to be one which is different from what we had before for application controller which

82
00:08:07,550 --> 00:08:15,200
was just V1 if you get this wrong you are likely to get an error that looks like this it would say no

83
00:08:15,200 --> 00:08:22,220
match for kind replica set because the specified carbonates API version has no support for replica set

84
00:08:23,890 --> 00:08:29,730
the kind would be replicas set and we add name and labels in the metadata

85
00:08:33,220 --> 00:08:39,140
the specification section looks very similar to replication controller it has a template section where

86
00:08:39,140 --> 00:08:42,230
we provide part definition as before.

87
00:08:42,500 --> 00:08:47,750
So I'm going to copy the contents over from part definition file and we have number of replicas which

88
00:08:47,750 --> 00:08:49,340
is set to three.

89
00:08:49,400 --> 00:08:56,660
However there is one major difference between replication controller and replica set has set requires

90
00:08:56,750 --> 00:09:06,610
a selector definition the selector section helps the replica set identify what parts fall under it but

91
00:09:06,610 --> 00:09:10,510
why would you have to specify what parts fall under it.

92
00:09:10,600 --> 00:09:18,170
If we have provided the contents of the part definition file itself in the template it's because replicas

93
00:09:18,180 --> 00:09:24,790
set can also manage parts that were not created as part of the replica at creation.

94
00:09:24,920 --> 00:09:32,360
Say for example the reports created before the creation of the replica set that match labels specified

95
00:09:32,360 --> 00:09:33,480
in the selector.

96
00:09:33,680 --> 00:09:39,010
The replica set will also take those parts into consideration when creating the replicas.

97
00:09:39,930 --> 00:09:46,170
I will elaborate this in the next slide but before we get into that I would like to mention that the

98
00:09:46,170 --> 00:09:52,770
selector is one of the major differences between replication controller and replica set the selector

99
00:09:52,800 --> 00:09:59,100
is not a required field in case of a replication controller but it is still available when you skip

100
00:09:59,100 --> 00:10:01,560
it as we did in the previous slide.

101
00:10:01,620 --> 00:10:08,910
It assumes it to be the same as the labels provided in the part definition file in case of replica said

102
00:10:09,120 --> 00:10:16,890
a user input is required for this property and it has to be written in the form of match labels as shown

103
00:10:16,890 --> 00:10:17,780
here.

104
00:10:17,970 --> 00:10:24,960
The match labeled selector simply matches the labels specified under it to the labels on the part.

105
00:10:24,960 --> 00:10:32,100
The replica set selector also provides many other options for matching labels that were not available

106
00:10:32,130 --> 00:10:33,060
in the replication.

107
00:10:33,060 --> 00:10:37,970
Controller and as always to create a replica set.

108
00:10:38,000 --> 00:10:45,020
Run the cube CTF and create command providing the definition file as input and to see the created replicas

109
00:10:45,080 --> 00:10:53,540
run the cubes TTL get replica set command to get list of parts simply run the cube control get parts.

110
00:10:53,540 --> 00:10:55,920
Command.

111
00:10:56,130 --> 00:10:59,620
So what is the deal with labels and selectors.

112
00:10:59,620 --> 00:11:03,060
Why do we label our parts and objects in corporate entities.

113
00:11:03,190 --> 00:11:05,510
Let us look at a simple scenario.

114
00:11:05,770 --> 00:11:12,660
Say we deployed three instances of our front end web application as three part.

115
00:11:12,760 --> 00:11:18,610
We would like to create a replication controller or replica set to ensure that we have three active

116
00:11:18,610 --> 00:11:20,770
parts at any time.

117
00:11:20,770 --> 00:11:24,300
And yes that is one of the use case of replica sets.

118
00:11:24,400 --> 00:11:27,460
You can use it to monitor existing parts.

119
00:11:27,490 --> 00:11:34,610
If you have them already created as cities in this example in case they were not created the replica

120
00:11:34,610 --> 00:11:37,190
set will create them for you.

121
00:11:37,310 --> 00:11:44,000
The role of the replica set is to monitor the parts and if any of them were to fail deploy new ones.

122
00:11:44,000 --> 00:11:49,570
The replica set is in fact a process that monitors the parts.

123
00:11:49,610 --> 00:11:51,050
Now how does the replica set.

124
00:11:51,230 --> 00:11:51,980
No.

125
00:11:52,010 --> 00:11:53,960
What part to monitor.

126
00:11:53,960 --> 00:11:59,450
There could be hundreds of other parts in the cluster running different applications.

127
00:11:59,450 --> 00:12:08,280
This is where labelling our parts during creation comes in handy we could now provide these labels as

128
00:12:08,280 --> 00:12:15,810
a filter for replica set under the selector section we use to match labels filter and provide the same

129
00:12:15,810 --> 00:12:18,980
label that we used while creating the parts.

130
00:12:19,140 --> 00:12:27,670
This way the replica set knows which parts to monitor the same concept of labels and selectors is used

131
00:12:27,760 --> 00:12:30,880
in many other places throughout Cuba.

132
00:12:30,880 --> 00:12:39,380
Notice now let me ask you a question along the same lines in the replica set specification section.

133
00:12:39,380 --> 00:12:45,150
We learned that there are three sections template replicas and the selector.

134
00:12:45,290 --> 00:12:50,990
We need three replicas and we have updated our selector based on our discussion in the previous slide

135
00:12:52,050 --> 00:12:58,260
say for instance we have the same scenario as in the previous slide where we have three existing parts

136
00:12:58,350 --> 00:13:05,100
that were created already and we need to create a replica set to monitor the parts to ensure there are

137
00:13:05,190 --> 00:13:10,860
a minimum of three running at all times when the replication controller is created.

138
00:13:10,890 --> 00:13:19,300
It is not going to deploy a new instance of part as three of them with matching labels are already created.

139
00:13:19,480 --> 00:13:26,320
In that case do we really need to provide a template section in the type replica set specification.

140
00:13:26,320 --> 00:13:32,960
Since we are not expecting the replica set to create a new port on deployment yes we do.

141
00:13:33,070 --> 00:13:40,180
Because in case one of the parts were to fail in the future the replicas that needs to create a new

142
00:13:40,180 --> 00:13:47,230
one to maintain the desired number of pods and for the replica set to create a new pod the template

143
00:13:47,260 --> 00:13:55,020
definition section is required let's now look at how we scaled the replica set.

144
00:13:55,260 --> 00:14:00,470
Say we started with three replicas in the future we decided to scale to six.

145
00:14:00,600 --> 00:14:05,310
How do we update our replica set to scale to six replicas.

146
00:14:05,310 --> 00:14:07,420
Well there are multiple ways to do it.

147
00:14:07,440 --> 00:14:12,660
The first is to update the number of replicas in the definition file to 6

148
00:14:15,340 --> 00:14:22,920
then run the cubes TTL replace command to specify the same file using the dash f parameter and that

149
00:14:22,920 --> 00:14:26,130
will update the replica set to have six replicas.

150
00:14:27,270 --> 00:14:31,890
The second way to do it is to run the cube control scale command.

151
00:14:32,080 --> 00:14:38,280
Use the replicas parameter to provide the new number of replicas and specify the same file as input

152
00:14:39,570 --> 00:14:47,870
human either input the definition file or provide the Republicans at name in the type name format however

153
00:14:47,990 --> 00:14:55,610
remember that using the file name as input will not result in the number of replicas being updated automatically

154
00:14:55,610 --> 00:14:56,960
in the file.

155
00:14:56,960 --> 00:15:03,410
In other words the number of friendly cars in the replica set definition file will still be three even

156
00:15:03,410 --> 00:15:09,260
though you scaled your replica set to have six replicas using the cube control scale command and the

157
00:15:09,260 --> 00:15:11,580
file as input.

158
00:15:11,590 --> 00:15:18,370
There are also options available for automatically scaling the replica set based on load but that is

159
00:15:18,370 --> 00:15:22,080
an advanced topic and we will discuss it at a later time.

160
00:15:23,280 --> 00:15:29,480
Let us now review the commands real quick the cube control create command as we know is used to create

161
00:15:29,480 --> 00:15:36,440
a replica set or basically any object in Cuba and it is depending on the file we are providing as input.

162
00:15:36,920 --> 00:15:44,130
You must provide the input file using the dash f parameter use the cube control get command to see List

163
00:15:44,130 --> 00:15:50,010
of replica sets created used to keep control delete replica set command followed by the name of the

164
00:15:50,010 --> 00:15:56,340
replica set to delete the replica set and then we have the cube controlled replace Command to replace

165
00:15:56,340 --> 00:16:03,480
or update the replica set and also the cube control scale command scale replica set simply from the

166
00:16:03,480 --> 00:16:09,020
command line without having to modify the file that's it for this lecture.
