1
00:00:02,090 --> 00:00:05,200
By now you saw some examples by Kubernetes

2
00:00:05,200 --> 00:00:07,970
and letting Kubernetes manage deployments

3
00:00:07,970 --> 00:00:10,430
for us could be useful.

4
00:00:10,430 --> 00:00:14,122
Now let me show you how we could actually change our code

5
00:00:14,122 --> 00:00:17,670
and update our deployment, and then even roll back

6
00:00:17,670 --> 00:00:19,975
to another of deployment if we wanted to

7
00:00:19,975 --> 00:00:22,573
because it's really, really easy.

8
00:00:23,520 --> 00:00:25,810
Let's say we changed our source code here

9
00:00:25,810 --> 00:00:29,360
and I have more exclamation marks and a new paragraph.

10
00:00:29,360 --> 00:00:31,838
This is new like this new, like this

11
00:00:31,838 --> 00:00:36,235
So I changed my source code and I saved that file.

12
00:00:36,235 --> 00:00:39,510
Now, of course, we need to rebuild our image.

13
00:00:39,510 --> 00:00:40,650
This doesn't change.

14
00:00:40,650 --> 00:00:43,820
That's always the case because our code is in the image.

15
00:00:43,820 --> 00:00:46,620
And if our container somewhere, no matter

16
00:00:46,620 --> 00:00:48,790
on which machine should be updated

17
00:00:48,790 --> 00:00:51,690
the image needs to be updated first.

18
00:00:51,690 --> 00:00:55,650
So I will update my academind/kub-first app image

19
00:00:55,650 --> 00:00:58,030
with Docker build by rebuilding it

20
00:00:58,030 --> 00:01:00,520
and using that latest source code.

21
00:01:00,520 --> 00:01:03,700
And now we want to update our deployment to

22
00:01:03,700 --> 00:01:07,980
take this new image this updated image into account.

23
00:01:07,980 --> 00:01:11,640
To update, a deployment, lets first of all,

24
00:01:11,640 --> 00:01:14,010
check whether the deployment is still there.

25
00:01:14,010 --> 00:01:16,200
Yes, it is this first step deployment here.

26
00:01:16,200 --> 00:01:17,579
And to update it

27
00:01:17,579 --> 00:01:20,710
we can now run the cube control set command

28
00:01:20,710 --> 00:01:24,852
and we can run it with image to set a new image

29
00:01:24,852 --> 00:01:29,103
for a specific deployment by targeting deployment slash

30
00:01:29,103 --> 00:01:34,103
and then the name of your deployment in my case first app.

31
00:01:34,110 --> 00:01:34,943
So with that

32
00:01:34,943 --> 00:01:37,390
I'm saying Kubernedes that I want to set a new image

33
00:01:37,390 --> 00:01:39,797
for a deployment, and after the slash

34
00:01:39,797 --> 00:01:41,950
the name of the deployment,

35
00:01:41,950 --> 00:01:44,163
this is the syntax for updating an image.

36
00:01:44,163 --> 00:01:45,180
But of course

37
00:01:45,180 --> 00:01:50,180
we now need to let Kuberenetes know what our new image is.

38
00:01:50,350 --> 00:01:51,560
Of course you could say

39
00:01:51,560 --> 00:01:54,870
well, we specify that when we created the deployment

40
00:01:54,870 --> 00:01:56,947
of course, it should always use the same image,

41
00:01:56,947 --> 00:01:59,736
and whilst this could be a logic you use

42
00:01:59,736 --> 00:02:03,050
it would also be pretty unflexible.

43
00:02:03,050 --> 00:02:04,480
If you ever want to switch

44
00:02:04,480 --> 00:02:06,530
to a different image with a different name

45
00:02:06,530 --> 00:02:09,570
or a different tech, you couldn't do that.

46
00:02:09,570 --> 00:02:13,820
That's why now in addition to what you wrote thus far,

47
00:02:13,820 --> 00:02:17,930
we need to let kubernetes know which current container

48
00:02:17,930 --> 00:02:21,370
and image to update with which future image.

49
00:02:21,370 --> 00:02:24,479
So for that we use the current container name, which

50
00:02:24,479 --> 00:02:26,010
in case you're not sure you can

51
00:02:26,010 --> 00:02:29,137
find in this web console it's kub-first app.

52
00:02:29,137 --> 00:02:32,500
So simply the image name we used before.

53
00:02:32,500 --> 00:02:34,530
So kub first app

54
00:02:34,530 --> 00:02:38,490
and we set this now equal to the new image we want to use,

55
00:02:38,490 --> 00:02:43,003
and that would be academind/kub-first app of course.

56
00:02:44,330 --> 00:02:47,610
Now of course, just like before this will pull the image

57
00:02:47,610 --> 00:02:49,870
from Docker hub, so first of all,

58
00:02:49,870 --> 00:02:54,310
we need to push our updated image to Docker hub

59
00:02:54,310 --> 00:02:56,370
with Docker push.

60
00:02:56,370 --> 00:02:59,100
So we built the image now we need to push it,

61
00:02:59,100 --> 00:03:03,290
and once that pushing finished, we can run the command

62
00:03:03,290 --> 00:03:04,513
I just showed you.

63
00:03:05,970 --> 00:03:10,930
So it is finished, now execute cube control set image

64
00:03:10,930 --> 00:03:15,410
deployment/first app old image name=new image,

65
00:03:15,410 --> 00:03:17,783
this will update the deployment.

66
00:03:18,913 --> 00:03:21,040
Now, once you executed this command

67
00:03:22,160 --> 00:03:25,190
if you get your deployments though

68
00:03:25,190 --> 00:03:27,271
you'll not notice any difference here,

69
00:03:27,271 --> 00:03:29,430
and if you visit your application

70
00:03:29,430 --> 00:03:32,027
you'll also not notice any difference here.

71
00:03:32,027 --> 00:03:33,780
Now, the reason for that is

72
00:03:33,780 --> 00:03:36,491
that actually new images will only be downloaded

73
00:03:36,491 --> 00:03:39,126
if they have a different tech.

74
00:03:39,126 --> 00:03:41,703
Now, there are ways of changing this,

75
00:03:41,703 --> 00:03:45,230
but it is a good idea to update your tags

76
00:03:45,230 --> 00:03:47,415
and kind of version your images anyways

77
00:03:47,415 --> 00:03:50,750
once you are working with a production setup,

78
00:03:50,750 --> 00:03:52,830
so therefore what do you want to do here

79
00:03:52,830 --> 00:03:55,090
is when we build our image

80
00:03:55,090 --> 00:03:58,520
with Docker build command, we want to give it a tag

81
00:03:58,520 --> 00:04:01,730
and it could simply be an incrementing version number.

82
00:04:01,730 --> 00:04:05,038
So let's now give it version two, for example.

83
00:04:05,038 --> 00:04:08,193
So I have column two after my name.

84
00:04:09,300 --> 00:04:13,630
Now we can push this new image with that tag at the end

85
00:04:14,670 --> 00:04:17,721
and now this latest image version will be pushed

86
00:04:17,721 --> 00:04:21,790
to my repository. With that done,

87
00:04:21,790 --> 00:04:25,150
we can repeat this set image command, to kub control

88
00:04:25,150 --> 00:04:29,010
set image command, and now specify this tag at the end.

89
00:04:29,010 --> 00:04:32,330
So column two here, this will now ensure

90
00:04:32,330 --> 00:04:35,120
that Kubernetes detects that it's a different tag

91
00:04:35,120 --> 00:04:38,634
and used before, and it will then re download this image

92
00:04:38,634 --> 00:04:41,469
and restart your containers based on that.

93
00:04:41,469 --> 00:04:45,926
So now you can see, we get this image updated confirmation.

94
00:04:45,926 --> 00:04:49,420
You can view the current updating status

95
00:04:49,420 --> 00:04:54,420
by executing kub control, rollout status deployment/

96
00:04:55,342 --> 00:04:59,070
and then the name of your deployment in our case first app.

97
00:04:59,070 --> 00:05:03,060
And you'll see here, it was rolled out successfully.

98
00:05:03,060 --> 00:05:06,000
And if you go back to your browser and you reload here

99
00:05:06,000 --> 00:05:07,090
maybe not immediately,

100
00:05:07,090 --> 00:05:11,423
but after some time you should see the updated output here.

101
00:05:12,630 --> 00:05:15,512
And if you go to your Kubernetes dashboard here

102
00:05:15,512 --> 00:05:17,790
and you have a look at your pods

103
00:05:17,790 --> 00:05:20,210
and you inspect this pod here

104
00:05:20,210 --> 00:05:23,202
under events, you can see that this new image was polled

105
00:05:23,202 --> 00:05:27,827
and that a new container was created, based on that image.

106
00:05:27,827 --> 00:05:28,660
You can also see that

107
00:05:28,660 --> 00:05:31,512
this is the image we're currently using here.

108
00:05:31,512 --> 00:05:34,040
So that's how we could now update the image,

109
00:05:34,040 --> 00:05:35,520
and therefore the source code

110
00:05:35,520 --> 00:05:39,220
off a container running as part of a pod managed

111
00:05:39,220 --> 00:05:44,046
by Kubernedes with this kub control set image command.

112
00:05:44,046 --> 00:05:47,500
Just keep in mind that you need to change your text

113
00:05:47,500 --> 00:05:51,693
to trigger kubernetes, to re download the image.

