1 00:00:02,570 --> 00:00:05,599 ‫So far, we've discussed that the YAML, there could 2 00:00:05,600 --> 00:00:08,299 ‫be...there's four root objects, and we've talked about 3 00:00:08,300 --> 00:00:09,740 ‫three of them briefly. 4 00:00:09,980 --> 00:00:11,869 ‫This is all about the spec. 5 00:00:12,200 --> 00:00:14,176 ‫The details of what you want it to do, right. 6 00:00:15,470 --> 00:00:18,214 ‫We first had the API, so we know what version of the API 7 00:00:18,260 --> 00:00:20,839 ‫we're talking to. We know what resource we want to talk to 8 00:00:20,850 --> 00:00:22,340 ‫and we're going to mess with. 9 00:00:22,370 --> 00:00:25,129 ‫Then, we know the name in the metadata. 10 00:00:25,190 --> 00:00:27,101 ‫We've got that. After that, the spec is 11 00:00:28,250 --> 00:00:29,960 ‫a whole world to explore. 12 00:00:30,440 --> 00:00:33,470 ‫The first command I want you to learn is simply 13 00:00:33,560 --> 00:00:36,590 ‫how to list all the different keys 14 00:00:36,860 --> 00:00:39,829 ‫that you can put for a particular resource type. 15 00:00:40,550 --> 00:00:43,535 ‫The first command I need you to learn the 16 00:00:43,863 --> 00:00:46,369 ‫kubectl explain, and then the resource type. 17 00:00:46,430 --> 00:00:48,050 ‫That's the kind in the YAML. 18 00:00:48,620 --> 00:00:49,620 ‫Then --recursive. 19 00:00:50,180 --> 00:00:52,939 ‫This will show you all the different keys 20 00:00:53,210 --> 00:00:55,310 ‫that it supports in the YAML file. 21 00:00:55,760 --> 00:00:58,504 ‫Just for services, you can see that it comes back with a 22 00:00:58,520 --> 00:01:00,950 ‫lot. It's a little bit overwhelming. 23 00:01:01,000 --> 00:01:02,030 ‫There's so much in there. 24 00:01:02,330 --> 00:01:04,219 ‫Of course, it doesn't tell us what those things do. 25 00:01:04,459 --> 00:01:06,615 ‫But, this is at least a quick list of all of 26 00:01:07,400 --> 00:01:09,948 ‫them. What this is good for for me is when I'm doing 27 00:01:10,460 --> 00:01:14,060 ‫my YAML building is if I can't remember exactly 28 00:01:14,330 --> 00:01:17,120 ‫the name of that thing, the creation timestamp. 29 00:01:17,210 --> 00:01:18,799 ‫Is it timestamp creation? 30 00:01:18,800 --> 00:01:20,122 ‫Is it plural? Is it singular? 31 00:01:20,900 --> 00:01:22,519 ‫You can just use this as a quick look up. 32 00:01:22,560 --> 00:01:24,979 ‫But, this isn't going to tell you what these things do, or 33 00:01:24,980 --> 00:01:26,689 ‫which ones are required or anything like that. 34 00:01:27,260 --> 00:01:30,290 ‫We can drill down using a slightly different command 35 00:01:30,590 --> 00:01:31,750 ‫and get more details. 36 00:01:32,210 --> 00:01:34,023 ‫Let's do the kubectl explain services 37 00:01:35,420 --> 00:01:38,660 ‫again, but this time, we're going to use a dot notation 38 00:01:38,870 --> 00:01:40,196 ‫to drill down in the YAML. 39 00:01:40,590 --> 00:01:43,848 ‫I'm going to say I only care about the spec. 40 00:01:44,090 --> 00:01:45,090 ‫I'm with you a .spec. 41 00:01:46,490 --> 00:01:49,482 ‫This time, I get back just the subkeys 42 00:01:50,570 --> 00:01:53,159 ‫of the spec and then a little description about them. 43 00:01:53,214 --> 00:01:55,879 ‫Then, what type of value they support, right. 44 00:01:55,880 --> 00:01:59,209 ‫Whether is it a Boolean? Is it a map of objects? 45 00:01:59,210 --> 00:02:02,449 ‫Stuff like that, right. It's just a nice little reference. 46 00:02:02,780 --> 00:02:04,969 ‫This is going to help you from jumping over to 47 00:02:04,970 --> 00:02:07,339 ‫documentation. You can avoid that a little bit by looking 48 00:02:07,340 --> 00:02:09,594 ‫here. This can still be a lot, especially when 49 00:02:10,340 --> 00:02:11,930 ‫you just want to look for one attribute. 50 00:02:12,230 --> 00:02:15,379 ‫You can keep drilling down that dot notation. 51 00:02:15,830 --> 00:02:19,129 ‫If we do spec.type, that is a particular 52 00:02:19,130 --> 00:02:22,400 ‫key inside of services YAML that 53 00:02:22,490 --> 00:02:25,249 ‫tells us the type of the load balancer. 54 00:02:25,280 --> 00:02:27,799 ‫If you remember this from talking about services earlier in 55 00:02:27,800 --> 00:02:31,069 ‫this course, this could be the cluster IP, by default. 56 00:02:31,280 --> 00:02:34,039 ‫If you just leave it out, it'll just do the cluster IP, or 57 00:02:34,040 --> 00:02:35,989 ‫a node port, or load balancer. 58 00:02:36,290 --> 00:02:38,090 ‫That's where you would specify that. 59 00:02:38,120 --> 00:02:41,089 ‫You know that it would have to go underneath spec 60 00:02:41,180 --> 00:02:44,449 ‫and then the key of type in your YAML file. 61 00:02:44,720 --> 00:02:47,540 ‫In this case, we could just start writing our YAML, right. 62 00:02:47,840 --> 00:02:50,059 ‫We know that the kind is going to be service. 63 00:02:50,390 --> 00:02:53,539 ‫The API version, it says here, is v1 for 64 00:02:53,540 --> 00:02:56,110 ‫this type. You could also verify that with the api-versions 65 00:02:57,350 --> 00:02:58,639 ‫command like we did earlier. 66 00:02:59,060 --> 00:03:00,320 ‫Then you can put in your value. 67 00:03:00,740 --> 00:03:03,919 ‫This lists the working value, so you know that 68 00:03:04,010 --> 00:03:07,369 ‫cluster IP is with a capital C and a capital IP, 69 00:03:07,640 --> 00:03:09,799 ‫stuff like that, right. Keeps you from going and 70 00:03:09,800 --> 00:03:11,629 ‫potentially searching all over the Internet. 71 00:03:11,960 --> 00:03:14,780 ‫You never know whether someone's going to be outdated or 72 00:03:14,810 --> 00:03:15,810 ‫correct at all. 73 00:03:16,220 --> 00:03:17,240 ‫This is how I like to do it. 74 00:03:18,020 --> 00:03:20,870 ‫Just to show how far this dot notation can go. 75 00:03:21,320 --> 00:03:23,525 ‫If we looked at a deployment spec, because it 76 00:03:24,290 --> 00:03:26,348 ‫has subspecs, which is something we hadn't 77 00:03:27,250 --> 00:03:30,521 ‫talked about. You can have a resource as a subobject 78 00:03:31,400 --> 00:03:32,629 ‫of another resource. 79 00:03:32,900 --> 00:03:35,810 ‫In this case, volumes, right, for storing the data. 80 00:03:36,080 --> 00:03:39,020 ‫We could have as many volumes as we want inside 81 00:03:39,320 --> 00:03:41,329 ‫a deployment, which it would then connect it to the 82 00:03:41,330 --> 00:03:44,419 ‫containers. Those are definitely 83 00:03:44,420 --> 00:03:46,580 ‫their own resource types, right, of volume. 84 00:03:46,659 --> 00:03:50,209 ‫In this case, we're going to see the spec twice. 85 00:03:50,780 --> 00:03:52,838 ‫If I were to hit enter on this command for 86 00:03:53,750 --> 00:03:56,569 ‫deployment.spec, one of the things in there 87 00:03:56,750 --> 00:03:57,750 ‫would be template. 88 00:03:58,730 --> 00:04:00,289 ‫Then I could just type template. 89 00:04:02,180 --> 00:04:04,939 ‫Then it would list all the different keys that I could put 90 00:04:04,940 --> 00:04:07,819 ‫in there, and one of them is spec 91 00:04:08,030 --> 00:04:09,030 ‫of the template. 92 00:04:09,340 --> 00:04:11,689 ‫Technically, we're in the spec of a spec. 93 00:04:12,170 --> 00:04:15,349 ‫Then underneath that spec for the template of a pod, 94 00:04:15,620 --> 00:04:17,958 ‫because a deployment has its own spec, and then the 95 00:04:17,959 --> 00:04:21,169 ‫template for the pods is underneath 96 00:04:21,170 --> 00:04:23,571 ‫that spec. Then it has a spec for the containers, 97 00:04:24,117 --> 00:04:27,049 ‫and I might have volumes in here. 98 00:04:27,410 --> 00:04:29,615 ‫So volumes and then nfs because that's a type 99 00:04:30,470 --> 00:04:31,609 ‫of volume I can use. 100 00:04:31,940 --> 00:04:34,421 ‫Then the server that I'm going to use inside in NFS. 101 00:04:35,450 --> 00:04:38,341 ‫Here we go. I could get the description and the information 102 00:04:38,750 --> 00:04:41,389 ‫about versions. By the way, this is another quirk with 103 00:04:41,690 --> 00:04:44,119 ‫Kubernetes is the documentation on the command lines is a 104 00:04:44,120 --> 00:04:46,880 ‫little outdated when it comes to versions which is why I 105 00:04:46,910 --> 00:04:49,605 ‫always use the API versions command, along with the API 106 00:04:50,060 --> 00:04:53,209 ‫resources. Because this is the old way 107 00:04:53,210 --> 00:04:55,724 ‫to do it before. They now have the new apps/v1 108 00:04:56,990 --> 00:04:59,719 ‫for deployments. I just happen to know that because I was 109 00:04:59,720 --> 00:05:02,449 ‫exploring why this was this way and it turns out that 110 00:05:02,630 --> 00:05:05,209 ‫they're keeping it this way in the documentation until it's 111 00:05:05,210 --> 00:05:06,279 ‫completely deprecated. 112 00:05:07,190 --> 00:05:09,248 ‫Anyway, you can see how I would eventually 113 00:05:10,160 --> 00:05:12,859 ‫work my way down the pipe with a dot notation. 114 00:05:12,890 --> 00:05:14,869 ‫I would just be deployment. Then I would look at that. 115 00:05:14,870 --> 00:05:16,850 ‫And then I would .spec, and so on and so forth. 116 00:05:17,180 --> 00:05:20,089 ‫That would be how I eventually find the right 117 00:05:20,450 --> 00:05:23,329 ‫keys and values to put in my YAML. 118 00:05:23,600 --> 00:05:26,839 ‫You can always go use other people's examples. 119 00:05:26,900 --> 00:05:29,540 ‫What you'll probably end up with is 120 00:05:29,900 --> 00:05:31,969 ‫you'll start out with some examples from either me or the 121 00:05:31,970 --> 00:05:32,970 ‫documentation. 122 00:05:33,230 --> 00:05:36,199 ‫Then you'll want to sort of see if you can 123 00:05:36,500 --> 00:05:39,709 ‫go from pure vanilla file using 124 00:05:39,710 --> 00:05:42,439 ‫my method here. Then you'll end up with your own little 125 00:05:42,440 --> 00:05:44,990 ‫resource, right. Your own little copy of all these resource 126 00:05:45,010 --> 00:05:48,379 ‫YAMLs. That your private repository 127 00:05:48,380 --> 00:05:51,059 ‫of knowledge. That'll be what you use in your company. 128 00:05:51,080 --> 00:05:53,432 ‫You might even have standards for how you create 129 00:05:53,600 --> 00:05:56,149 ‫deployments and standards for how you create services. 130 00:05:56,450 --> 00:05:59,329 ‫Maybe they'll have special labels or annotations on them, 131 00:05:59,570 --> 00:06:00,709 ‫which we haven't yet talked about. 132 00:06:00,920 --> 00:06:03,049 ‫They'll maybe have a special template features. 133 00:06:03,350 --> 00:06:06,241 ‫Anyway. There's lots you could do there, but most teams end 134 00:06:06,290 --> 00:06:08,749 ‫up with their own defaults in a repo of sorts that they 135 00:06:08,750 --> 00:06:11,959 ‫pull from rather than completely typing from scratch. 136 00:06:12,130 --> 00:06:14,509 ‫Right. We don't do that with compose and we certainly 137 00:06:14,510 --> 00:06:16,600 ‫aren't going to want to do that with the YAML here in 138 00:06:16,930 --> 00:06:20,029 ‫Kubernetes. The last little tip I'll give you here is if 139 00:06:20,030 --> 00:06:22,189 ‫you're more on the developer side of things, you will 140 00:06:22,190 --> 00:06:25,069 ‫always appreciate the API documentation, 141 00:06:25,310 --> 00:06:27,620 ‫which you can get all this same data from. 142 00:06:27,920 --> 00:06:30,860 ‫It's just not necessarily in a way that a more 143 00:06:31,040 --> 00:06:33,709 ‫operating-focused person would understand. 144 00:06:34,160 --> 00:06:36,559 ‫I come from both backgrounds, but I can definitely see how 145 00:06:36,560 --> 00:06:38,929 ‫the API documentation can be a little intimidating to 146 00:06:38,930 --> 00:06:40,939 ‫someone who's not used to reading swagger 147 00:06:42,020 --> 00:06:45,350 ‫and all these other types of documentation for APIs. 148 00:06:45,770 --> 00:06:48,171 ‫Here, I'm just going to pick, for example, on the 149 00:06:48,620 --> 00:06:51,619 ‫Kubernetes reference for the API under 150 00:06:51,650 --> 00:06:53,650 ‫115, so that's versioned. 151 00:06:54,080 --> 00:06:56,040 ‫I could see here, on the left, a menu of 152 00:06:57,260 --> 00:06:58,534 ‫all the workload API. 153 00:06:58,880 --> 00:07:00,529 ‫These are going to be most of the things you'll be dealing 154 00:07:00,530 --> 00:07:03,910 ‫with. Then there's service API. 155 00:07:03,980 --> 00:07:07,279 ‫These things go on top of your workloads, 156 00:07:07,310 --> 00:07:10,005 ‫like the services, or the ingress, endpoint, stuff like 157 00:07:10,160 --> 00:07:12,949 ‫that. Then you have configs and storage down here. 158 00:07:12,950 --> 00:07:16,519 ‫As you go, you'll actually get to more deprecated 159 00:07:16,520 --> 00:07:18,470 ‫or legacy API versions. 160 00:07:18,890 --> 00:07:21,113 ‫You could explore whether...you'll see in here like a lot 161 00:07:21,114 --> 00:07:22,399 ‫of these alphas and betas. 162 00:07:22,700 --> 00:07:24,740 ‫You can kind of figure out which ones are there. 163 00:07:25,040 --> 00:07:27,529 ‫If I just went up to deployment real quick 164 00:07:28,190 --> 00:07:31,789 ‫and came here, I could get some kubectl examples 165 00:07:31,790 --> 00:07:32,899 ‫of what it might look like. 166 00:07:34,960 --> 00:07:36,669 ‫I could also scroll down here 167 00:07:38,249 --> 00:07:39,249 ‫and look for the spec. 168 00:07:39,960 --> 00:07:42,449 ‫The spec of something is where you're going to get all that 169 00:07:42,450 --> 00:07:44,699 ‫detail that we were looking at earlier. 170 00:07:45,000 --> 00:07:47,970 ‫Underneath the spec, you'll see all these different 171 00:07:48,000 --> 00:07:50,459 ‫options for that particular object. 172 00:07:50,730 --> 00:07:53,309 ‫If I dive into the template of the deployment spec, if you 173 00:07:53,310 --> 00:07:55,229 ‫remember from a while ago when I was following the dot 174 00:07:55,230 --> 00:07:57,762 ‫notation, that'll go into the pod template. 175 00:07:58,380 --> 00:08:00,830 ‫Then we'll jump over here into that and you'll see 176 00:08:01,380 --> 00:08:03,689 ‫all these things jumping into that template, and so on and 177 00:08:03,690 --> 00:08:06,385 ‫so forth. It requires you to dig around a little bit to 178 00:08:06,540 --> 00:08:09,284 ‫figure out and find the objects and the keys that you're 179 00:08:09,420 --> 00:08:12,213 ‫looking for. I find that it's a little bit easier to work 180 00:08:12,310 --> 00:08:14,880 ‫from the command line, but the command line 181 00:08:15,360 --> 00:08:16,560 ‫also doesn't deal with the versions. 182 00:08:16,620 --> 00:08:19,315 ‫If you've got a different version of a client then your 183 00:08:19,680 --> 00:08:22,649 ‫server version, you'll want to definitely look at the API 184 00:08:22,650 --> 00:08:25,949 ‫docs because your client might be on an older 185 00:08:25,950 --> 00:08:28,649 ‫or newer version than what your server can support. 186 00:08:29,160 --> 00:08:31,619 ‫There's no real way, at the command line that I'm aware of, 187 00:08:31,620 --> 00:08:34,919 ‫to get the different versions of the information. 188 00:08:35,039 --> 00:08:36,629 ‫It's always just the version of your client.