1 00:00:02,311 --> 00:00:04,075 ‫Similar to Docker Swarm in, it using 2 00:00:05,580 --> 00:00:08,969 ‫replicas as the term for the different containers 3 00:00:08,970 --> 00:00:11,939 ‫running and deciding how to scale up and 4 00:00:11,940 --> 00:00:14,831 ‫scale down using the number of replicas, and also the scale 5 00:00:15,000 --> 00:00:17,549 ‫command. We had that similar experience with 6 00:00:18,090 --> 00:00:21,420 ‫Kubernetes. Let's check out the kubectl command line 7 00:00:21,660 --> 00:00:22,660 ‫and how that's going to work. 8 00:00:23,070 --> 00:00:24,770 ‫First we're going to need to start a new Deployment. 9 00:00:25,320 --> 00:00:28,260 ‫So, let's go back and do a kubectl run 10 00:00:28,680 --> 00:00:29,680 ‫my-apache. 11 00:00:31,220 --> 00:00:32,650 ‫-- image httpd. 12 00:00:33,757 --> 00:00:36,409 ‫Unlike Nginx, we're going to run an Apache web server this 13 00:00:36,410 --> 00:00:39,679 ‫time, mostly just because it does give us some default 14 00:00:39,680 --> 00:00:41,900 ‫logging out-of-the-box so we can at least look at logs. 15 00:00:47,520 --> 00:00:50,610 ‫We can check that all those objects have been deployed with 16 00:00:50,730 --> 00:00:52,380 ‫another get all. 17 00:00:56,050 --> 00:00:57,961 ‫Once your desired and current are ready 18 00:00:59,020 --> 00:01:01,959 ‫to go on your ReplicaSet, as well as the pod, 19 00:01:02,290 --> 00:01:04,989 ‫then we know we're ready to do the next command. 20 00:01:05,349 --> 00:01:07,015 ‫This default run gives us a single 21 00:01:08,530 --> 00:01:09,760 ‫pod or replica. 22 00:01:10,090 --> 00:01:11,559 ‫Let's scale that up to 2. 23 00:01:18,660 --> 00:01:21,899 ‫Notice that I typed --replicas 2 here with the scale 24 00:01:21,900 --> 00:01:24,630 ‫command. I also put in 25 00:01:24,990 --> 00:01:26,159 ‫the type of object. 26 00:01:26,250 --> 00:01:28,289 ‫In other words, a Deployment, and then the name of that 27 00:01:28,290 --> 00:01:30,719 ‫Deployment. But there's a different format you noticed I've 28 00:01:30,720 --> 00:01:33,171 ‫used here. I've used a deploy rather than Deployment, 29 00:01:33,930 --> 00:01:36,629 ‫and I've used a forward slash rather than a space. 30 00:01:37,080 --> 00:01:40,409 ‫This goes into a little discussion around the flexibility 31 00:01:40,410 --> 00:01:41,489 ‫of the Kubernetes command line. 32 00:01:41,970 --> 00:01:44,669 ‫You'll notice that a lot of commands have short versions of 33 00:01:44,670 --> 00:01:45,670 ‫the command itself. 34 00:01:46,170 --> 00:01:49,020 ‫Different parts of the command can be abbreviated or 35 00:01:49,290 --> 00:01:52,500 ‫substituted in various ways like a slash versus a space. 36 00:01:52,560 --> 00:01:54,520 ‫Stuff like that. In this case, the scale 37 00:01:55,860 --> 00:01:58,980 ‫deploy / my-apache would be the same as 38 00:01:59,220 --> 00:02:02,400 ‫scale space deployment space my-apache. 39 00:02:03,450 --> 00:02:05,012 ‫Those would be the same equivalent. 40 00:02:05,013 --> 00:02:08,099 ‫You can basically in a lot of places where you would 41 00:02:08,100 --> 00:02:10,592 ‫see the Deployment option, you might be able to specify 42 00:02:10,593 --> 00:02:12,896 ‫deploy, deployment or deployments in the plural 43 00:02:13,680 --> 00:02:16,530 ‫state. You'll notice that this is sometimes 44 00:02:16,830 --> 00:02:19,760 ‫similar in other parts of the command line where plural or 45 00:02:19,770 --> 00:02:21,419 ‫singular work just as well. 46 00:02:21,870 --> 00:02:25,050 ‫Or, sometimes you can abbreviate part of the command. 47 00:02:25,500 --> 00:02:27,839 ‫Honestly, over the years, this has changed. 48 00:02:28,110 --> 00:02:31,349 ‫So, it's not so obvious which parts you can abbreviate or 49 00:02:31,620 --> 00:02:33,360 ‫put in a slash for a space. 50 00:02:33,900 --> 00:02:36,389 ‫But, I think once you get used to your own way of doing 51 00:02:36,390 --> 00:02:37,939 ‫things, that'll just work for you. 52 00:02:39,350 --> 00:02:42,439 ‫Now, if we do a quick kubectl get all again. 53 00:02:43,800 --> 00:02:45,719 ‫You'll notice that we have two pods now. 54 00:02:45,990 --> 00:02:48,419 ‫You'll see that the ReplicaSet at the bottom has a desired 55 00:02:48,420 --> 00:02:50,639 ‫state of two and two are running. 56 00:02:50,970 --> 00:02:54,059 ‫In the general concept here, this is exactly 57 00:02:54,060 --> 00:02:57,029 ‫what Swarm services do. They scale up and down replicas 58 00:02:57,030 --> 00:02:58,320 ‫based on your requirements. 59 00:02:58,710 --> 00:03:01,919 ‫In this case, we're just talking about pods 60 00:03:02,130 --> 00:03:03,330 ‫rather than tasks. 61 00:03:03,660 --> 00:03:06,599 ‫When we did the scale command, let me give you the basics 62 00:03:06,660 --> 00:03:08,139 ‫of what went on in the background. 63 00:03:08,520 --> 00:03:10,823 ‫Because we have extra levels of abstraction, we 64 00:03:11,490 --> 00:03:13,919 ‫need to understand how these levels react to each other. 65 00:03:14,190 --> 00:03:16,229 ‫When we typed the scale command, we were technically 66 00:03:16,260 --> 00:03:18,479 ‫updating the Deployment spec. 67 00:03:19,280 --> 00:03:21,210 ‫In Kubernetes, everything has a spec. 68 00:03:21,720 --> 00:03:24,354 ‫This spec for the Deployment changed the 69 00:03:25,350 --> 00:03:28,589 ‫ReplicaSet to a set of two replicas. 70 00:03:29,090 --> 00:03:31,638 ‫Then that ReplicaSet controller decided to change it 71 00:03:32,070 --> 00:03:35,099 ‫to two pods, and there would be one pod 72 00:03:35,100 --> 00:03:36,100 ‫for each replica. 73 00:03:36,570 --> 00:03:39,389 ‫Then the control plane makes a decision about which nodes, 74 00:03:39,420 --> 00:03:41,999 ‫in this case you've only got one node, but which nodes 75 00:03:42,030 --> 00:03:44,009 ‫would get assigned those pods. 76 00:03:44,370 --> 00:03:46,720 ‫Then if you had a multi-node setup, the kubelet 77 00:03:47,340 --> 00:03:50,340 ‫agent would then get assigned that pod and would 78 00:03:50,640 --> 00:03:53,279 ‫take that for execution to create the container on his 79 00:03:53,280 --> 00:03:54,280 ‫local Docker Engine. 80 00:03:55,230 --> 00:03:57,876 ‫While it seems like this is a lot of work going on the 81 00:03:57,900 --> 00:04:00,689 ‫background simply to start another container, it actually 82 00:04:00,690 --> 00:04:03,779 ‫happens really fast. In fact, it happens almost as fast 83 00:04:03,840 --> 00:04:06,809 ‫as Swarm. Generally, we're talking about 84 00:04:07,170 --> 00:04:09,689 ‫a second, two seconds, something like that when you're 85 00:04:09,690 --> 00:04:10,919 ‫talking about a single machine. 86 00:04:11,220 --> 00:04:14,459 ‫With Swarm, one of the advantages it has is that everything 87 00:04:14,670 --> 00:04:16,259 ‫is in the single binary. 88 00:04:16,470 --> 00:04:18,929 ‫So, it happens a lot quicker because it's really just 89 00:04:18,930 --> 00:04:21,599 ‫happening inside the same process including the launching 90 00:04:21,600 --> 00:04:22,600 ‫of the container itself. 91 00:04:23,040 --> 00:04:25,379 ‫With Kubernetes, we get these additional layers of 92 00:04:25,380 --> 00:04:28,350 ‫abstraction. That does introduce 93 00:04:28,380 --> 00:04:30,830 ‫a slight delay compared to maybe something you would do 94 00:04:31,260 --> 00:04:32,260 ‫Docker or Swarm. 95 00:04:32,610 --> 00:04:34,160 ‫But really, in most cases, it's negligible. 96 00:04:34,980 --> 00:04:38,069 ‫The tradeoff is we get much more flexibility and control 97 00:04:38,070 --> 00:04:39,600 ‫with these different layers of abstraction. 98 00:04:40,430 --> 00:04:42,420 ‫Oh! Don't clean up on this one. 99 00:04:42,450 --> 00:04:44,655 ‫We're going to use these Apache containers in 100 00:04:45,510 --> 00:04:48,401 ‫the next lecture when we do some inspecting of what's going 101 00:04:48,510 --> 00:04:49,038 ‫on in Kubernetes.