1 00:00:02,590 --> 00:00:05,432 ‫Hopefully this YAML stuff is starting to make a little bit 2 00:00:05,440 --> 00:00:08,739 ‫of sense, and this is where we learn how 3 00:00:08,740 --> 00:00:11,169 ‫to create essentially this YAML from scratch. 4 00:00:11,470 --> 00:00:14,020 ‫When I started learning the Kubernetes 5 00:00:14,560 --> 00:00:17,499 ‫YAML format, I first started off just using 6 00:00:17,530 --> 00:00:20,229 ‫documentation examples, right, from their docs on the 7 00:00:20,470 --> 00:00:23,100 ‫kubernetes.io site, or maybe from other places. 8 00:00:23,110 --> 00:00:26,109 ‫The thing about other places is, just like Docker, is those 9 00:00:26,110 --> 00:00:28,660 ‫blogs and other stuff, they all get outdated. 10 00:00:29,050 --> 00:00:31,809 ‫The thing about Kubernetes is some of these things have 11 00:00:31,810 --> 00:00:34,029 ‫changed over time, especially when it comes to things like 12 00:00:34,030 --> 00:00:37,239 ‫deployments, and pods and other core 13 00:00:37,240 --> 00:00:39,089 ‫stuff. They've tweaked their formats. 14 00:00:39,190 --> 00:00:40,739 ‫The versions in the API have changed. 15 00:00:40,740 --> 00:00:42,210 ‫We want to stay on the current 16 00:00:43,840 --> 00:00:46,509 ‫stuff, which means you need to know how to start from 17 00:00:46,510 --> 00:00:49,989 ‫scratch. How do you know when your files need to change 18 00:00:50,230 --> 00:00:52,419 ‫rather than just going and rereading the documentation 19 00:00:52,420 --> 00:00:54,369 ‫randomly to see if anything's changed, right. 20 00:00:54,760 --> 00:00:57,729 ‫This part is, I think, a skill that it took me a 21 00:00:57,730 --> 00:01:00,580 ‫while to figure this stuff out, and how to 22 00:01:00,910 --> 00:01:03,458 ‫build a file without using some sort of pre-existing 23 00:01:03,880 --> 00:01:07,209 ‫template. We talked about the four types in the last 24 00:01:07,210 --> 00:01:10,029 ‫lecture, and that root key of kind, 25 00:01:10,180 --> 00:01:12,639 ‫which is the resource type, is what I want to focus on 26 00:01:12,640 --> 00:01:15,489 ‫first. Because you can get a list of those in a cluster. 27 00:01:15,940 --> 00:01:18,341 ‫In our setup test clusters, most of these will be 28 00:01:18,940 --> 00:01:20,170 ‫the same between all of us. 29 00:01:20,200 --> 00:01:22,709 ‫As you get into production and you start adding third-party 30 00:01:23,050 --> 00:01:26,319 ‫stuff to your cluster, this list will get longer 31 00:01:26,350 --> 00:01:29,379 ‫depending on what you're using because third 32 00:01:29,380 --> 00:01:32,290 ‫party tools can add new resource objects 33 00:01:32,530 --> 00:01:33,530 ‫to the API. 34 00:01:33,910 --> 00:01:35,160 ‫Let's do a kubectl api-resources. 35 00:01:37,270 --> 00:01:40,239 ‫You'll get back at least dozens 36 00:01:40,240 --> 00:01:43,119 ‫of different objects that we could scroll through and talk 37 00:01:43,120 --> 00:01:44,120 ‫about for hours. 38 00:01:44,410 --> 00:01:45,520 ‫We're not going to do that. 39 00:01:45,760 --> 00:01:48,348 ‫We've already talked about a few of them like Deployments, 40 00:01:48,550 --> 00:01:51,549 ‫and Pods, and ReplicaSets and Services. 41 00:01:52,210 --> 00:01:54,339 ‫Those are the standard out-of-the-box things. 42 00:01:54,640 --> 00:01:57,489 ‫A lot of the rest of this you may never touch. 43 00:01:57,520 --> 00:01:59,499 ‫That's the thing about Kubernetes is there's just so much 44 00:01:59,500 --> 00:02:01,558 ‫to it that you may never actually need all 45 00:02:02,500 --> 00:02:05,409 ‫the power from it. It's not that important that you go 46 00:02:05,410 --> 00:02:06,909 ‫through and memorize all of these. 47 00:02:07,090 --> 00:02:09,491 ‫You'll notice this kind column over on the right. 48 00:02:09,956 --> 00:02:12,969 ‫That's what goes in our YAML file. 49 00:02:13,000 --> 00:02:16,479 ‫If we want to create a pod, you can see that there's a kind 50 00:02:16,480 --> 00:02:18,894 ‫pod here. If we want to create a deployment, there 51 00:02:19,510 --> 00:02:21,459 ‫is a kind called deployment. 52 00:02:21,820 --> 00:02:24,009 ‫You'll also see the API group. 53 00:02:24,370 --> 00:02:27,639 ‫That API group is related to the API 54 00:02:27,640 --> 00:02:29,409 ‫version. You'll see that in a second. 55 00:02:29,920 --> 00:02:33,459 ‫This doesn't exactly give us a prescriptive manual 56 00:02:33,520 --> 00:02:36,362 ‫necessarily. But, if I was sitting here and I said, I need 57 00:02:36,550 --> 00:02:40,120 ‫to create a pod, I would look through this list for pods 58 00:02:40,540 --> 00:02:42,069 ‫in the type of resources. 59 00:02:42,100 --> 00:02:44,439 ‫I would see the kind that it is. 60 00:02:44,500 --> 00:02:45,790 ‫That's what I know I need to put in my YAML. 61 00:02:46,870 --> 00:02:49,509 ‫I would see if there's any API group because that's going 62 00:02:49,510 --> 00:02:52,599 ‫to tell me where to find the versions 63 00:02:52,630 --> 00:02:54,729 ‫that I can use, because you probably have seen different 64 00:02:54,730 --> 00:02:57,189 ‫documentation for let's say a deployment. 65 00:02:57,460 --> 00:03:00,310 ‫Because deployments had multiple versions over time. 66 00:03:00,340 --> 00:03:03,240 ‫There was a v1beta1, a v1beta2. 67 00:03:03,850 --> 00:03:06,849 ‫It's actually even moved around in the API because there's 68 00:03:07,180 --> 00:03:09,699 ‫old stuff and new stuff, so it can be a little confusing. 69 00:03:09,970 --> 00:03:12,789 ‫If you look at this list, you'll actually find that there 70 00:03:12,790 --> 00:03:14,949 ‫are deployments up here, 71 00:03:15,820 --> 00:03:17,740 ‫and there are deployments down here. 72 00:03:18,640 --> 00:03:21,759 ‫The only difference between the two is this middle 73 00:03:21,760 --> 00:03:24,039 ‫row, the API group. 74 00:03:24,580 --> 00:03:27,550 ‫That API group is where in the API 75 00:03:27,850 --> 00:03:30,153 ‫this type of resource can be accessed, created, 76 00:03:30,932 --> 00:03:32,289 ‫deleted, etc. 77 00:03:33,040 --> 00:03:36,129 ‫This gets a little bit into the weeds, but once 78 00:03:36,130 --> 00:03:38,139 ‫you start working with this stuff, you're going to have to 79 00:03:38,140 --> 00:03:40,780 ‫spend a little bit of time when you see cases like 80 00:03:41,470 --> 00:03:42,888 ‫seeing two types of deployments here. 81 00:03:42,889 --> 00:03:44,199 ‫Which one do I use? 82 00:03:44,230 --> 00:03:46,629 ‫Well, you start to go and do research and you'll find, 83 00:03:46,660 --> 00:03:49,509 ‫either in the documentation, or in the API 84 00:03:49,840 --> 00:03:51,759 ‫guide itself, which we'll look at in a little bit. 85 00:03:52,060 --> 00:03:54,826 ‫You'll see that stuff where it'll tell you one's 86 00:03:55,060 --> 00:03:57,559 ‫deprecated, and one is moving to another one and in 87 00:03:58,030 --> 00:04:00,940 ‫this case with deployments, the new version of it, in the 88 00:04:01,000 --> 00:04:03,879 ‫latest version, is the app's API. 89 00:04:04,240 --> 00:04:06,739 ‫The next command that goes along with that, to help 90 00:04:07,270 --> 00:04:10,210 ‫us get a better picture of kind, plus 91 00:04:10,510 --> 00:04:13,599 ‫API version, is the kubectl API 92 00:04:13,630 --> 00:04:14,630 ‫versions command. 93 00:04:19,450 --> 00:04:22,819 ‫That gives us a shorter list which is just 94 00:04:22,820 --> 00:04:25,779 ‫the different versions of APIs that we need to 95 00:04:25,780 --> 00:04:28,509 ‫worry about. In the case of deployments, 96 00:04:28,810 --> 00:04:31,750 ‫you'll see on here that there's something familiar. 97 00:04:32,010 --> 00:04:34,839 ‫Remember, we saw that there was an apps one, and there was 98 00:04:34,840 --> 00:04:36,490 ‫an extensions one for deployments. 99 00:04:36,790 --> 00:04:38,200 ‫We'll see those show up here. 100 00:04:38,410 --> 00:04:41,182 ‫Technically, there's the extensions of v1beta1 101 00:04:41,380 --> 00:04:44,529 ‫API. There is the apps API 102 00:04:44,590 --> 00:04:46,690 ‫of which you can see three different versions there. 103 00:04:47,050 --> 00:04:49,452 ‫You probably would want to use the V1 apps, 104 00:04:50,590 --> 00:04:51,910 ‫not the older betas. 105 00:04:52,120 --> 00:04:55,209 ‫But, you can see where the API is sort of holding 106 00:04:55,210 --> 00:04:58,540 ‫on to deprecated versions of this API 107 00:04:58,600 --> 00:04:59,825 ‫as it rolls out new ones. 108 00:04:59,860 --> 00:05:03,250 ‫That way, basically, your old YAML isn't broke until 109 00:05:03,520 --> 00:05:06,426 ‫many versions go by and they pull stuff out of the API 110 00:05:06,464 --> 00:05:08,439 ‫once it's no longer needed. 111 00:05:09,190 --> 00:05:11,983 ‫What typically happens over the lifetime of your YAML, if 112 00:05:12,160 --> 00:05:15,039 ‫you were on the early days of Kubernetes, is you might have 113 00:05:15,040 --> 00:05:17,950 ‫been using a YAML file that said 114 00:05:18,190 --> 00:05:19,190 ‫extensions/v1beta1 115 00:05:21,640 --> 00:05:24,579 ‫for the API version, and the kind 116 00:05:24,640 --> 00:05:25,640 ‫was deployments. 117 00:05:25,900 --> 00:05:28,105 ‫But, as that API has changed, and they're now 118 00:05:29,080 --> 00:05:32,019 ‫calling it the apps API, and 119 00:05:32,230 --> 00:05:35,349 ‫the version is different, you would still have kind 120 00:05:35,350 --> 00:05:38,529 ‫of deployment, but you would change that API version 121 00:05:38,530 --> 00:05:41,049 ‫to be apps/v1 now. 122 00:05:41,320 --> 00:05:43,868 ‫The way I know that is because I had to do searching 123 00:05:44,470 --> 00:05:45,949 ‫and you'd look at the documentation. 124 00:05:45,980 --> 00:05:47,949 ‫You see in the examples that, oh hey. 125 00:05:47,950 --> 00:05:49,959 ‫It says apps now. It doesn't say extensions anymore. 126 00:05:49,990 --> 00:05:52,330 ‫That's weird. Let me go look it up. Then you find some 127 00:05:52,660 --> 00:05:55,089 ‫Kubernetes issues in GitHub that talk about it. 128 00:05:55,540 --> 00:05:58,269 ‫It's a little messy. There's not always a clear 129 00:05:58,720 --> 00:06:01,299 ‫deprecation list of everything that's changing all the 130 00:06:01,300 --> 00:06:04,300 ‫time, so it can be something that is a problem. 131 00:06:04,630 --> 00:06:06,849 ‫The way that you'll know that this doesn't work is when you 132 00:06:06,850 --> 00:06:09,545 ‫take an old YAML and you apply it to a new cluster, and 133 00:06:09,940 --> 00:06:11,998 ‫it will tell you, I don't support this API 134 00:06:12,940 --> 00:06:16,000 ‫version anymore. Or, I don't know what this kind is. 135 00:06:16,270 --> 00:06:18,519 ‫So, it'll give you a nice errors that lets you know that, 136 00:06:18,520 --> 00:06:20,169 ‫hey that's the problem. Then, you can probably do some 137 00:06:20,170 --> 00:06:22,149 ‫quick searching and find out what's outdated. 138 00:06:22,640 --> 00:06:24,747 ‫The point I'm making is that the kind, plus 139 00:06:25,600 --> 00:06:28,540 ‫the API version, are used together to 140 00:06:28,780 --> 00:06:31,870 ‫decide which resource you're going to get and which API 141 00:06:31,900 --> 00:06:34,180 ‫version you're going to be able to use for that resource. 142 00:06:34,450 --> 00:06:36,399 ‫Those are the first two things you need to figure out 143 00:06:36,550 --> 00:06:37,600 ‫before you even create a YAML. 144 00:06:38,200 --> 00:06:39,789 ‫Once you have that, then you're going to create the 145 00:06:39,790 --> 00:06:42,681 ‫metadata part. The only thing you have to have there is the 146 00:06:42,730 --> 00:06:44,302 ‫name of the resource you're going to create. 147 00:06:44,303 --> 00:06:45,730 ‫Just give it a nice name. 148 00:06:46,060 --> 00:06:48,369 ‫Then, you're going to go to the spec. That's where all of 149 00:06:48,370 --> 00:06:51,099 ‫the action is at because the spec is going to be completely 150 00:06:51,100 --> 00:06:53,230 ‫different based on the resource you're creating. 151 00:06:53,440 --> 00:06:56,800 ‫If you're creating storage versus a deployment, 152 00:06:56,950 --> 00:06:58,757 ‫you can imagine how the YAML would be quite different, 153 00:06:58,758 --> 00:06:59,758 ‫right. 154 00:07:00,070 --> 00:07:02,880 ‫In the next lecture, we're going to go through some kubectl 155 00:07:03,160 --> 00:07:06,399 ‫commands to help you explore the API 156 00:07:06,430 --> 00:07:09,489 ‫for all the different spec stuff that you can put 157 00:07:09,490 --> 00:07:11,889 ‫into your YAML for different resources.