1 00:00:02,550 --> 00:00:05,369 ‫Because of the immense flexibility we have with 2 00:00:05,660 --> 00:00:08,759 ‫Kubernetes, there's lots of styles for how you 3 00:00:08,760 --> 00:00:11,519 ‫do your work in the Kubernetes cluster system. 4 00:00:11,760 --> 00:00:13,240 ‫You've heard me talk about that before, right. 5 00:00:13,470 --> 00:00:16,019 ‫I've told you that there are different ways to fit your 6 00:00:16,020 --> 00:00:18,030 ‫workflow, and that you can use different commands in 7 00:00:18,031 --> 00:00:20,489 ‫different ways. So, that can be challenging when you're 8 00:00:20,490 --> 00:00:22,949 ‫trying to teach it because people really want to know how 9 00:00:22,950 --> 00:00:25,279 ‫they're supposed to be using it. Like what's the best way? 10 00:00:25,290 --> 00:00:27,899 ‫What's the best practice? That's hard because 11 00:00:28,260 --> 00:00:29,919 ‫it really depends on what you want out of it. 12 00:00:29,920 --> 00:00:31,929 ‫It's it it's an unappealing dated system. 13 00:00:31,980 --> 00:00:34,020 ‫So, there's lots of different ways to do stuff. 14 00:00:34,710 --> 00:00:35,950 ‫This is where I try to break that down. 15 00:00:35,970 --> 00:00:38,069 ‫So, this one's a key important one. 16 00:00:38,160 --> 00:00:39,629 ‫But, this is all just slide learning. 17 00:00:39,630 --> 00:00:41,999 ‫This is going to be me talking at you for a few minutes to 18 00:00:42,000 --> 00:00:44,793 ‫try to break down these concepts and apply what they mean 19 00:00:44,850 --> 00:00:46,229 ‫to Kubernetes specifically. 20 00:00:46,500 --> 00:00:49,680 ‫Before we get to recommended approaches, and 21 00:00:49,890 --> 00:00:52,379 ‫there's basically going to end up being three recommended 22 00:00:52,380 --> 00:00:54,290 ‫strategies for how to use Kubernetes. 23 00:00:54,930 --> 00:00:56,789 ‫This is where I need to break down some of these terms so 24 00:00:56,790 --> 00:00:58,979 ‫you know what that next lecture is. 25 00:00:59,280 --> 00:01:01,485 ‫You'll see this in a lot of blog posts and in 26 00:01:02,114 --> 00:01:04,559 ‫documentation. Imperative versus Declarative. 27 00:01:04,920 --> 00:01:07,979 ‫The best way that describes it, in relation 28 00:01:08,040 --> 00:01:10,049 ‫to Kubernetes, is to back up and just say 29 00:01:11,010 --> 00:01:12,394 ‫what it means in terms of software. 30 00:01:13,250 --> 00:01:16,379 ‫When we're writing software imperatively, we're focused 31 00:01:16,410 --> 00:01:19,680 ‫on the how of that program operating, 32 00:01:19,740 --> 00:01:22,529 ‫each step, in order, one after the other. 33 00:01:22,980 --> 00:01:25,650 ‫When we talk about a declarative approach to software, 34 00:01:25,980 --> 00:01:28,709 ‫we're describing more about what it should accomplish. 35 00:01:28,900 --> 00:01:30,072 ‫What are its end goals? 36 00:01:30,510 --> 00:01:33,569 ‫We don't care so much how it gets there just that it 37 00:01:33,570 --> 00:01:36,420 ‫does get there. Let's try an analogy. 38 00:01:36,780 --> 00:01:38,430 ‫Imagine you want a cup of coffee. 39 00:01:38,640 --> 00:01:40,859 ‫When I wake up every morning, I'm looking for that first 40 00:01:40,860 --> 00:01:43,114 ‫cup. If I'm going to make it myself, I'm going 41 00:01:43,980 --> 00:01:45,204 ‫to have to do it imperatively. 42 00:01:45,660 --> 00:01:47,640 ‫I'm going to have to think about boiling some water. 43 00:01:47,910 --> 00:01:50,219 ‫What's the next step? Well, I need some coffee beans. 44 00:01:50,280 --> 00:01:52,739 ‫Then I've got to grind those beans. How much exactly do I 45 00:01:52,740 --> 00:01:55,799 ‫need? How much water do I pour over those beans to get 46 00:01:55,800 --> 00:01:58,439 ‫the perfect cup of coffee, etc, right. 47 00:01:58,590 --> 00:02:01,409 ‫I'm going through each step, and I'm thinking about how 48 00:02:01,410 --> 00:02:02,669 ‫it's done, step by step. 49 00:02:03,000 --> 00:02:05,399 ‫That's imperative. When you look at Kubernetes, we'll talk 50 00:02:05,400 --> 00:02:06,400 ‫about that in a second. 51 00:02:07,200 --> 00:02:10,020 ‫Declarative mode. Think of it as more of 52 00:02:10,190 --> 00:02:12,330 ‫maybe I'm at a coffee shop and I'm talking to a barista. 53 00:02:12,900 --> 00:02:14,580 ‫I'm simply asking them. 54 00:02:14,700 --> 00:02:15,809 ‫I'd like a cup of coffee. 55 00:02:16,200 --> 00:02:18,307 ‫My only job is to ask for the cup of coffee 56 00:02:19,242 --> 00:02:21,919 ‫and it's up to them to figure out, hey. 57 00:02:21,990 --> 00:02:24,689 ‫Do I need to make it from scratch? Is there one already 58 00:02:24,690 --> 00:02:26,450 ‫made in the pot? Or is the pot too old? 59 00:02:26,452 --> 00:02:29,429 ‫They can do...they can...maybe have to retry 60 00:02:29,430 --> 00:02:31,589 ‫three times to make the cup of coffee because they messed 61 00:02:31,590 --> 00:02:33,089 ‫it up. That's fine. 62 00:02:33,180 --> 00:02:34,979 ‫I'm not asking how they make it. 63 00:02:35,280 --> 00:02:37,889 ‫I'm asking for them to produce me a cup of coffee. 64 00:02:38,310 --> 00:02:41,103 ‫Let's apply this to the commands you're going to be using 65 00:02:41,490 --> 00:02:44,610 ‫in Kubernetes. Let's focus on imperative, 66 00:02:44,970 --> 00:02:47,763 ‫which is what you've largely been learning so far because 67 00:02:48,120 --> 00:02:51,270 ‫it's the way to start learning any tool is 68 00:02:51,800 --> 00:02:54,209 ‫imperatively. You're going to be doing these things in the 69 00:02:54,210 --> 00:02:57,003 ‫order they need to be done, and you're giving it explicit 70 00:02:57,150 --> 00:02:59,070 ‫instructions on how to do it. 71 00:02:59,640 --> 00:03:02,295 ‫These commands, like kubectl run, and create deployment, 72 00:03:02,296 --> 00:03:05,460 ‫and update, which we haven't yet covered, or edit. 73 00:03:05,730 --> 00:03:07,799 ‫These are the different types of commands that will have 74 00:03:07,800 --> 00:03:10,919 ‫you starting in a state that you know. 75 00:03:11,100 --> 00:03:13,444 ‫When you use a create deployment command, you 76 00:03:14,070 --> 00:03:16,499 ‫know that the deployment isn't yet created. 77 00:03:16,560 --> 00:03:19,409 ‫Thus, you are using the create, right. 78 00:03:19,650 --> 00:03:23,190 ‫If you want to update, or edit something, you're explicitly 79 00:03:23,370 --> 00:03:25,289 ‫using that command to do that. 80 00:03:25,590 --> 00:03:28,470 ‫The nice thing here for command line and typing into the 81 00:03:28,480 --> 00:03:31,371 ‫CLI is that different commands are used for different types 82 00:03:31,650 --> 00:03:33,870 ‫of actions, whether it's create, or update, or delete. 83 00:03:34,170 --> 00:03:36,719 ‫That's easier for our brains to remember because we know 84 00:03:36,720 --> 00:03:37,889 ‫the action we're taking. 85 00:03:38,190 --> 00:03:40,889 ‫Just remember that imperative is easier when you already 86 00:03:40,890 --> 00:03:44,069 ‫know the state of the object or the resource, and 87 00:03:44,130 --> 00:03:46,939 ‫you're just getting started with using the tools. 88 00:03:46,940 --> 00:03:49,619 ‫So, you want to think explicitly, OK, I need to create a 89 00:03:49,620 --> 00:03:51,899 ‫service and that service needs to be a load balancer. 90 00:03:52,210 --> 00:03:54,809 ‫You know that kind of thing. Then, it's easier for us in 91 00:03:54,810 --> 00:03:57,122 ‫our human minds to type these things at the CLI. 92 00:03:58,230 --> 00:04:01,199 ‫It's unfortunately not easy 93 00:04:01,200 --> 00:04:03,944 ‫to automate. That's one of the biggest drawbacks to this 94 00:04:04,410 --> 00:04:06,566 ‫type of work is that it's really hard to get 95 00:04:07,470 --> 00:04:10,110 ‫an automated script, or tool, to 96 00:04:10,560 --> 00:04:13,059 ‫automatically handle the, Oh is this an update that 97 00:04:13,590 --> 00:04:15,509 ‫you want? Or is this a create? 98 00:04:15,540 --> 00:04:17,338 ‫Or is this a delete? Like you know, what am I supposed to 99 00:04:17,339 --> 00:04:19,642 ‫do here? It's hard for us to automate that type 100 00:04:20,459 --> 00:04:21,810 ‫of work. It's easy in our heads. 101 00:04:23,380 --> 00:04:24,869 ‫Easy for us to type at the CLI. Hard for us to automate. 102 00:04:25,250 --> 00:04:28,589 ‫Remember, declarative means we don't really know the state. 103 00:04:28,660 --> 00:04:30,569 ‫Remember the coffee. I don't know whether they have coffee 104 00:04:30,570 --> 00:04:32,249 ‫or not. They may already have some made. They may have to 105 00:04:32,250 --> 00:04:33,250 ‫make some from scratch. 106 00:04:33,690 --> 00:04:34,799 ‫I don't know the state. 107 00:04:35,010 --> 00:04:37,380 ‫I just know the end result that I want. 108 00:04:37,680 --> 00:04:40,490 ‫That's really fitting for a declarative model. 109 00:04:40,950 --> 00:04:43,400 ‫Some of the benefits here for us, and for automation, are 110 00:04:43,890 --> 00:04:46,589 ‫that the same command, usually you are going to be using 111 00:04:46,680 --> 00:04:49,019 ‫the apply command, kubectl apply. 112 00:04:49,410 --> 00:04:52,139 ‫That same command can be used regardless of whether we're 113 00:04:52,140 --> 00:04:54,541 ‫creating, or updating, or even possibly deleting, 114 00:04:55,110 --> 00:04:57,899 ‫resources. If you started looking at YAML, which we're 115 00:04:57,900 --> 00:04:59,249 ‫going to get into here in a minute. 116 00:04:59,580 --> 00:05:01,501 ‫That YAML can either be in a single file. 117 00:05:02,180 --> 00:05:04,459 ‫You can bundle lots of different types of resources into a 118 00:05:04,460 --> 00:05:07,459 ‫single YAML. Or, you can break them out into a single 119 00:05:07,490 --> 00:05:10,381 ‫object in each YAML file in a single directory, and you can 120 00:05:10,400 --> 00:05:12,740 ‫use one command to apply the entire directory. 121 00:05:12,790 --> 00:05:14,180 ‫There's lots of options there. 122 00:05:14,690 --> 00:05:17,660 ‫The reasons we don't get started using this method 123 00:05:17,690 --> 00:05:20,089 ‫is that one, we don't always need. 124 00:05:20,090 --> 00:05:22,639 ‫It it adds a little bit of complexity because you have to 125 00:05:22,640 --> 00:05:25,279 ‫create this file, and all of the stuff in, it before you 126 00:05:25,280 --> 00:05:26,280 ‫can even do it. 127 00:05:26,810 --> 00:05:29,260 ‫You may not have those from scratch, and you don't 128 00:05:29,570 --> 00:05:31,339 ‫necessarily want to create them just to create a pod or 129 00:05:31,340 --> 00:05:34,519 ‫something, right. So, getting started, the CLI makes sense. 130 00:05:34,550 --> 00:05:36,769 ‫Using the standard imperative commands makes sense. 131 00:05:37,040 --> 00:05:39,740 ‫But, as you start to think about production, and 132 00:05:39,770 --> 00:05:42,829 ‫automation, and doing this repetitive update process 133 00:05:42,830 --> 00:05:45,529 ‫over and over, like you're going to, then you start to 134 00:05:45,530 --> 00:05:48,529 ‫think about, OK. I need a more declarative approach. 135 00:05:48,860 --> 00:05:51,101 ‫The challenge there is you have to know all those YAML keys 136 00:05:52,400 --> 00:05:54,829 ‫and settings, and you kind of just have to start from 137 00:05:54,830 --> 00:05:57,949 ‫scratch and build up your expertise over time into all 138 00:05:57,950 --> 00:05:59,740 ‫the ways and things that you need to put in this YAML. 139 00:05:59,741 --> 00:06:02,689 ‫The great thing here is that your 140 00:06:02,690 --> 00:06:05,689 ‫investment is not wasted. While you're getting some 141 00:06:05,690 --> 00:06:08,312 ‫basic things done in Kubernetes now by typing the CLI's 142 00:06:08,900 --> 00:06:10,819 ‫like kubectl run or create. 143 00:06:11,510 --> 00:06:13,970 ‫Over that time, you're looking at YAML with the 144 00:06:14,540 --> 00:06:16,287 ‫output command, remember the -o yaml. 145 00:06:16,288 --> 00:06:18,040 ‫You can look at the output of the YAML. 146 00:06:18,560 --> 00:06:19,820 ‫There's other ways we can look at YAML. 147 00:06:20,540 --> 00:06:23,221 ‫We start building up our knowledge of what that YAML is 148 00:06:23,300 --> 00:06:26,449 ‫supposed to look like so that once you get to the world 149 00:06:26,480 --> 00:06:29,480 ‫in production where you're basically doing YAML all day, 150 00:06:30,010 --> 00:06:32,629 ‫you're going to be a little bit more familiar with the way 151 00:06:32,630 --> 00:06:34,443 ‫it's broken out. This YAML way is the 152 00:06:35,660 --> 00:06:38,540 ‫easiest way to automate your orchestration. 153 00:06:38,750 --> 00:06:41,855 ‫This is also the easiest way to get-ops 154 00:06:42,230 --> 00:06:44,719 ‫happiness. We won't talk a lot about get-ops in this 155 00:06:44,720 --> 00:06:47,420 ‫course. I recommend you go Google that because 156 00:06:47,720 --> 00:06:50,652 ‫it is a type of doing DevOps 157 00:06:50,960 --> 00:06:53,839 ‫work that uses the get tool as 158 00:06:53,930 --> 00:06:55,579 ‫your source of truth. 159 00:06:55,850 --> 00:06:57,919 ‫Basically, every time you want to make a change to your 160 00:06:57,920 --> 00:06:59,320 ‫environment, you edit some YAML. 161 00:07:00,030 --> 00:07:01,279 ‫You do the apply command. 162 00:07:01,310 --> 00:07:04,005 ‫You do a get-commit. Now you have this get-log of every 163 00:07:04,250 --> 00:07:07,043 ‫single thing you've done. That's one of the attributes of 164 00:07:07,160 --> 00:07:10,639 ‫the get-ops model of operations and doing 165 00:07:10,640 --> 00:07:13,129 ‫this with declarative is how you get there. 166 00:07:13,310 --> 00:07:16,369 ‫Let's look at the three ways that the Kubernetes teams 167 00:07:16,460 --> 00:07:19,040 ‫think we should be using the Kubernetes command line.