1 00:00:02,580 --> 00:00:04,932 ‫Oh man. I bet you've been waiting to just get to 2 00:00:05,610 --> 00:00:07,840 ‫the Kubernetes command line for a while now. 3 00:00:07,890 --> 00:00:10,049 ‫But luckily, we've got some of the concepts out of the way. 4 00:00:10,050 --> 00:00:11,460 ‫So, let's get to the command line. 5 00:00:12,000 --> 00:00:14,219 ‫The first thing we need to make sure is that whatever 6 00:00:14,220 --> 00:00:17,100 ‫you've done with setting up Kubernetes, that it's running. 7 00:00:17,670 --> 00:00:21,030 ‫The way we can do that is similar to the Docker version 8 00:00:21,060 --> 00:00:23,219 ‫and the Compose version and stuff like that. 9 00:00:23,640 --> 00:00:26,291 ‫We can go to the shell and type in kubectl, 10 00:00:26,820 --> 00:00:29,753 ‫that's K U B E C T 11 00:00:30,105 --> 00:00:31,979 ‫L version. You should get back to versions. 12 00:00:32,009 --> 00:00:34,655 ‫This is just like with Docker where you get the client 13 00:00:35,070 --> 00:00:36,450 ‫version and then the server version. 14 00:00:36,870 --> 00:00:39,659 ‫Remember that all these command line tools are doing 15 00:00:39,960 --> 00:00:41,436 ‫is talking to a remote API. 16 00:00:42,210 --> 00:00:44,729 ‫In this case, it's probably the API on your machine. 17 00:00:45,060 --> 00:00:48,210 ‫Just like with Docker, and Swarm, and Compose, 18 00:00:48,600 --> 00:00:51,609 ‫the kubectl command line can also talk to remote 19 00:00:51,630 --> 00:00:52,680 ‫Kubernetes API. 20 00:00:53,340 --> 00:00:55,290 ‫Now that you've gotten back the client server versions, 21 00:00:55,350 --> 00:00:58,143 ‫you're good to go. If you got an error, it would probably 22 00:00:58,170 --> 00:01:00,869 ‫be because the server version doesn't show up and it says 23 00:01:00,870 --> 00:01:03,089 ‫it can't connect. That means that somehow, you're 24 00:01:03,090 --> 00:01:06,270 ‫misconfigured and your local CLI can't talk 25 00:01:06,510 --> 00:01:09,179 ‫to the Kubernetes servers. I would either check how you 26 00:01:09,180 --> 00:01:11,040 ‫deployed it to make sure that it's running. 27 00:01:11,370 --> 00:01:13,939 ‫Maybe if you're on Docker Desktop, you need to start Docker 28 00:01:13,950 --> 00:01:16,289 ‫and then also make sure in the settings that Kubernetes is 29 00:01:16,290 --> 00:01:18,985 ‫running. If it's some other way, just check the install 30 00:01:19,290 --> 00:01:21,980 ‫video. If you have any issues with that, reach out in the Q 31 00:01:21,999 --> 00:01:23,100 ‫& A or in Slack. 32 00:01:23,630 --> 00:01:26,619 ‫All right. There's two ways to deploy pods in 33 00:01:26,950 --> 00:01:29,189 ‫Kubernetes, really. There's doing it at the command line 34 00:01:29,190 --> 00:01:31,836 ‫where you're specifying all the options at the command 35 00:01:32,040 --> 00:01:33,320 ‫line. Or, there's using YAML. 36 00:01:34,260 --> 00:01:37,469 ‫This might be similar in concept to services 37 00:01:37,500 --> 00:01:40,195 ‫and stacks in Swarm, but of course, when you really get 38 00:01:40,530 --> 00:01:42,389 ‫down to it, there's a lot of different stuff under the 39 00:01:42,390 --> 00:01:44,639 ‫covers. So, I hate to make that analogy, but that's really 40 00:01:44,640 --> 00:01:46,450 ‫the two options you have is either command line or YAML. 41 00:01:47,250 --> 00:01:49,529 ‫Let's focus on the command line for a few minutes. 42 00:01:50,010 --> 00:01:52,169 ‫The first command we're going to run here is 43 00:01:53,540 --> 00:01:54,540 ‫kubectl run. 44 00:01:55,270 --> 00:01:56,640 ‫So, it's similar to a docker run. 45 00:01:57,330 --> 00:02:00,209 ‫My Nginx, and you can call it whatever you want. 46 00:02:00,240 --> 00:02:02,720 ‫This is the name of your deployment. And then --image, 47 00:02:04,560 --> 00:02:06,230 ‫and we'll specify the image name here. 48 00:02:06,240 --> 00:02:09,509 ‫Let's just use Nginx like we're used to and hit return. 49 00:02:15,466 --> 00:02:18,063 ‫For a minute, let's ignore the depreciated warning if 50 00:02:18,490 --> 00:02:20,590 ‫you're getting that in some of the recent versions of 51 00:02:20,890 --> 00:02:22,840 ‫Kubernetes. We'll talk about that in a little bit. 52 00:02:23,230 --> 00:02:25,719 ‫But for now, let's see what just happened. 53 00:02:26,020 --> 00:02:28,749 ‫We can use that with the kubectl get command. 54 00:02:36,194 --> 00:02:37,879 ‫kubectl get pods. 55 00:02:40,160 --> 00:02:43,139 ‫What you should see there is you're 56 00:02:43,200 --> 00:02:46,379 ‫named object, along with some characters 57 00:02:46,380 --> 00:02:48,870 ‫on the end of it, and you'll see that 1 in 1 is running. 58 00:02:48,890 --> 00:02:52,169 ‫This is very similar to the services concept 59 00:02:52,170 --> 00:02:55,259 ‫in Swarm where we by default just 60 00:02:55,260 --> 00:02:56,729 ‫ran one replica. 61 00:02:56,996 --> 00:02:58,729 ‫You can see it's name there. 62 00:02:58,740 --> 00:02:59,880 ‫Why do we have that weird name? 63 00:03:00,810 --> 00:03:03,618 ‫Well, this has to do with the way that the kubectl 64 00:03:04,230 --> 00:03:05,550 ‫run command works. 65 00:03:05,960 --> 00:03:08,519 ‫When you're using the run as it is right now in Version 66 00:03:08,520 --> 00:03:11,789 ‫1.14, that is technically 67 00:03:11,820 --> 00:03:13,619 ‫using a Deployment controller. 68 00:03:14,220 --> 00:03:17,519 ‫That Deployment controller creates a ReplicaSet controller. 69 00:03:17,860 --> 00:03:20,729 ‫That ReplicateSet controller then creates the pods. 70 00:03:20,850 --> 00:03:23,129 ‫In this case, it's just one replica. 71 00:03:23,190 --> 00:03:24,190 ‫So, it's only one pod. 72 00:03:24,900 --> 00:03:27,572 ‫If we did a kubectl get all, you 73 00:03:31,850 --> 00:03:34,039 ‫would then see all the objects there listed. 74 00:03:34,130 --> 00:03:35,390 ‫You'll see pods. 75 00:03:35,840 --> 00:03:37,250 ‫Ignore the service for now. 76 00:03:37,270 --> 00:03:38,360 ‫We'll talk about that in a little bit. 77 00:03:38,990 --> 00:03:40,441 ‫The Deployment and in the ReplicaSet. 78 00:03:41,390 --> 00:03:43,399 ‫You can see these different layers of the 79 00:03:44,360 --> 00:03:47,509 ‫object model and Kubernetes coming out here where we just 80 00:03:47,510 --> 00:03:50,149 ‫did a single command, but it actually created multiple 81 00:03:50,150 --> 00:03:51,150 ‫objects for us. 82 00:03:51,680 --> 00:03:53,885 ‫Let's go to my drawing board and describe how 83 00:03:54,740 --> 00:03:56,060 ‫these objects relate to each other. 84 00:03:57,130 --> 00:04:00,099 ‫As you've seen in Kubernetes, we have more levels 85 00:04:00,100 --> 00:04:03,249 ‫of abstraction and control than we did previously 86 00:04:03,250 --> 00:04:04,749 ‫in Swarm or in Docker itself. 87 00:04:05,350 --> 00:04:08,379 ‫In this case, when we did the kubectl run, 88 00:04:08,980 --> 00:04:10,940 ‫it, in the background, created multiple, 89 00:04:12,010 --> 00:04:13,960 ‫different abstractions automatically for us. 90 00:04:14,470 --> 00:04:17,419 ‫It created the pod, but it also created around that a 91 00:04:17,860 --> 00:04:19,778 ‫ReplicaSet, and around that, a Deployment. 92 00:04:20,279 --> 00:04:23,410 ‫Let's go to the drawing board, and I'll show you how these 93 00:04:23,890 --> 00:04:25,360 ‫abstractions relate to each other. 94 00:04:27,624 --> 00:04:29,759 ‫As a reminder, we have Docker running underneath. 95 00:04:30,000 --> 00:04:33,300 ‫Then we have some containers running that are managing 96 00:04:34,130 --> 00:04:35,354 ‫Kubernetes, and I won't talk about those right now. 97 00:04:35,771 --> 00:04:38,700 ‫Let's just know that we have this different set 98 00:04:38,760 --> 00:04:41,480 ‫of containers over here just to run Kube. 99 00:04:42,600 --> 00:04:45,479 ‫When we did the kubectl run, 100 00:04:46,440 --> 00:04:49,125 ‫what it created was obviously our Nginx container, that 101 00:04:49,410 --> 00:04:51,139 ‫was the part that we know about. 102 00:04:51,570 --> 00:04:54,917 ‫But, the different levels of control, or abstractions, 103 00:04:55,320 --> 00:04:56,320 ‫are the interesting part. 104 00:04:57,090 --> 00:04:59,326 ‫The first one here is the pod. 105 00:05:02,040 --> 00:05:05,009 ‫Again, it can run one or more containers inside this pod. 106 00:05:05,730 --> 00:05:08,699 ‫As a part of that pod, it could have created volumes if 107 00:05:08,700 --> 00:05:11,360 ‫we needed it. It created the NIC 108 00:05:11,850 --> 00:05:12,850 ‫for the pod. 109 00:05:13,910 --> 00:05:16,160 ‫The way it created that pod was when we typed 110 00:05:16,970 --> 00:05:19,639 ‫kubectl run, it created 111 00:05:20,030 --> 00:05:21,030 ‫a Deployment. 112 00:05:21,710 --> 00:05:25,065 ‫A Deployment controller manages ReplicaSets. 113 00:05:25,670 --> 00:05:27,124 ‫We have multiple levels of abstraction. 114 00:05:31,290 --> 00:05:33,838 ‫That Deployment was created, and it does things like 115 00:05:34,020 --> 00:05:36,930 ‫rolling updates, or Blue/Green Deploys, and 116 00:05:36,990 --> 00:05:39,783 ‫a lot of other things that you think about when you think 117 00:05:39,870 --> 00:05:42,600 ‫about orchestration services like we had in Swarm services. 118 00:05:43,590 --> 00:05:46,440 ‫When that Deployment was created, it created a ReplicaSet 119 00:05:46,710 --> 00:05:47,710 ‫of one. 120 00:05:50,130 --> 00:05:52,109 ‫That itself is another controller. 121 00:05:55,907 --> 00:05:58,602 ‫The ReplicaSet's job is to make sure that the number of 122 00:05:58,810 --> 00:06:01,000 ‫pods we asked for are currently running. 123 00:06:01,480 --> 00:06:03,189 ‫In this case, we left everything at the default. 124 00:06:03,580 --> 00:06:06,229 ‫So, our Deployment created one ReplicaSet, and that 125 00:06:06,250 --> 00:06:08,067 ‫ReplicaSet created one pod. 126 00:06:09,070 --> 00:06:11,569 ‫We could control each one of these different levels 127 00:06:12,220 --> 00:06:14,817 ‫of abstraction. We could type commands to control the 128 00:06:14,950 --> 00:06:17,574 ‫Deployment. The ReplicaSet, or the pod itself directly, but 129 00:06:18,640 --> 00:06:21,069 ‫usually in these situations, you're always going to be 130 00:06:21,070 --> 00:06:22,690 ‫managing the Deployment itself. 131 00:06:23,200 --> 00:06:24,850 ‫Then it will take care of the rest. 132 00:06:25,270 --> 00:06:28,240 ‫To give you an idea of why the ReplicaSet itself 133 00:06:28,300 --> 00:06:31,269 ‫in the middle exists, is if we wanted to 134 00:06:31,270 --> 00:06:34,269 ‫create another copy of this pod, just like 135 00:06:34,270 --> 00:06:36,879 ‫when we do Swarm service replicas. 136 00:06:38,250 --> 00:06:40,014 ‫In my drawing here, I created a copy 137 00:06:41,670 --> 00:06:42,670 ‫of that pod. 138 00:06:42,930 --> 00:06:45,809 ‫That would be if we scaled the replicas to two. 139 00:06:46,080 --> 00:06:47,373 ‫Very similar to how Swarm does it. 140 00:06:47,374 --> 00:06:49,040 ‫The ReplicaSet's job, again, is to 141 00:06:50,370 --> 00:06:52,869 ‫ensure that two pods are running with the identical 142 00:06:53,820 --> 00:06:55,927 ‫template. The Deployment's job is to manage 143 00:06:56,790 --> 00:06:58,290 ‫the ReplicaSet configuration. 144 00:06:59,950 --> 00:07:03,129 ‫Before we jump to the next lecture, let's delete all 145 00:07:03,130 --> 00:07:05,542 ‫of these resources we just created with the run command by 146 00:07:06,220 --> 00:07:07,300 ‫using the delete command. 147 00:07:07,690 --> 00:07:09,551 ‫This is different than Docker where Docker had the remove 148 00:07:09,581 --> 00:07:10,581 ‫command. 149 00:07:11,050 --> 00:07:13,290 ‫Now, we're using a delete command with kubectl. 150 00:07:21,040 --> 00:07:23,839 ‫You'll notice that we're specifying the type of object and 151 00:07:23,840 --> 00:07:26,260 ‫then the name of itself. So, we're doing deployment space, 152 00:07:26,270 --> 00:07:27,289 ‫the name of the Deployment. 153 00:07:27,740 --> 00:07:30,582 ‫When you do that, it will delete all the things underneath 154 00:07:30,680 --> 00:07:33,522 ‫it. The ReplicaSet, the pods themselves and the containers 155 00:07:33,560 --> 00:07:34,560 ‫in them. 156 00:07:34,790 --> 00:07:37,939 ‫We can verify that quickly with the same get all command. 157 00:07:39,622 --> 00:07:42,680 ‫You'll only see the cluster IP there, which is the 158 00:07:43,030 --> 00:07:43,999 ‫Kubernetes server itself.