1 00:00:02,035 --> 00:00:05,170 ‫So far with Kubernetes, we haven't really discussed 2 00:00:05,180 --> 00:00:06,180 ‫storage or volumes. 3 00:00:07,121 --> 00:00:09,522 ‫You've dealt with that with Docker, and then with 4 00:00:10,150 --> 00:00:13,269 ‫Compose, and Swarm and to a 5 00:00:13,280 --> 00:00:14,487 ‫certain extent, it's the same thing in Kubernetes. 6 00:00:16,590 --> 00:00:18,279 ‫You have containers, and we assume that the containers are 7 00:00:18,280 --> 00:00:19,939 ‫stateless, meaning that when you throw the container away, 8 00:00:19,940 --> 00:00:21,272 ‫everything in it goes away. 9 00:00:21,800 --> 00:00:24,249 ‫When you replace a container with an update, or you change 10 00:00:24,250 --> 00:00:27,729 ‫something and you apply it with a kubectl apply, you 11 00:00:27,730 --> 00:00:28,743 ‫lose the container, you lose everything in it. 12 00:00:29,750 --> 00:00:31,932 ‫Obviously, Kubernetes, just like the other orchestrators, 13 00:00:32,110 --> 00:00:34,119 ‫have to have a way for persistent data to 14 00:00:35,140 --> 00:00:37,805 ‫stick around. It's even more than the volumes themselves. 15 00:00:39,070 --> 00:00:41,500 ‫Even the containers and deployments can be different in 16 00:00:41,540 --> 00:00:42,990 ‫Kubernetes with something called a StatefulSets. 17 00:00:43,690 --> 00:00:45,540 ‫These are resources 18 00:00:47,230 --> 00:00:48,300 ‫that are different than deployments. 19 00:00:48,840 --> 00:00:52,809 ‫They basically are designed around databases and 20 00:00:52,810 --> 00:00:55,213 ‫things that require much more persistence, including the 21 00:00:55,214 --> 00:00:57,241 ‫same name, same IPs stuff like that. 22 00:00:57,580 --> 00:00:59,529 ‫We didn't get that out-of-the-gate with Swarm or with 23 00:00:59,530 --> 00:01:00,530 ‫Docker necessarily. 24 00:01:00,960 --> 00:01:03,851 ‫It didn't really have a way for you to keep those different 25 00:01:04,120 --> 00:01:06,390 ‫attributes between containers. 26 00:01:06,670 --> 00:01:09,284 ‫StatefulSets is a new feature in Kubernetes 27 00:01:09,820 --> 00:01:12,670 ‫that has only been out a little bit of time here. 28 00:01:13,470 --> 00:01:15,793 ‫It's what you would look at if you're going to consider 29 00:01:15,794 --> 00:01:19,209 ‫databases or something that's very sensitive to changes 30 00:01:19,210 --> 00:01:22,003 ‫like names, and IP addresses, and volumes, and persistent 31 00:01:22,330 --> 00:01:23,831 ‫data. A word of caution here. 32 00:01:25,190 --> 00:01:27,787 ‫The reason we're not going to go through a lot of the 33 00:01:27,793 --> 00:01:31,419 ‫details of it is because I don't recommend that your 34 00:01:31,420 --> 00:01:33,453 ‫first deployment of Kubernetes involves a lot of 35 00:01:34,090 --> 00:01:36,981 ‫StatefulSets in it. In fact, ideally, your first deployment 36 00:01:37,450 --> 00:01:39,838 ‫of an orchestrator, of any orchestrator, whether it's Swarm 37 00:01:40,750 --> 00:01:43,396 ‫or Kubernetes, is only involved with stateless and you 38 00:01:43,860 --> 00:01:46,720 ‫know, keep it simple. Maybe just do your web frontends or 39 00:01:46,730 --> 00:01:49,260 ‫some APIs, or some worker features, or something 40 00:01:50,950 --> 00:01:53,319 ‫that don't involve databases. In fact, if you can use cloud 41 00:01:53,320 --> 00:01:54,420 ‫databases, do that. 42 00:01:55,730 --> 00:01:57,971 ‫I always recommend outsourcing your databases unless you 43 00:01:57,972 --> 00:02:00,226 ‫have specific requirements that you just can't 44 00:02:01,060 --> 00:02:03,810 ‫avoid for running yourself. Orchestration, initially, 45 00:02:05,560 --> 00:02:08,402 ‫was really designed around containers being immutable, and 46 00:02:08,919 --> 00:02:10,110 ‫distributed, and replaceable. 47 00:02:10,280 --> 00:02:12,791 ‫This idea of stickiness for statefulness 48 00:02:14,930 --> 00:02:16,520 ‫is going to add more work, and complexity, and 49 00:02:18,100 --> 00:02:20,439 ‫a lot more testing for you. Ideally, out-of-the-gate, you 50 00:02:20,440 --> 00:02:21,544 ‫don't have to worry about this. 51 00:02:21,760 --> 00:02:24,969 ‫Later on, once you're much more comfortable with all the 52 00:02:24,970 --> 00:02:27,074 ‫other things around Kubernetes, then you can come back and 53 00:02:27,075 --> 00:02:28,870 ‫say, now I want to consider my databases. 54 00:02:29,190 --> 00:02:31,440 ‫It's not that you shouldn't run databases in clusters. 55 00:02:31,690 --> 00:02:33,720 ‫It's just more work. It's harder. 56 00:02:34,110 --> 00:02:36,301 ‫Databases and persistent storage is always harder 57 00:02:38,650 --> 00:02:40,409 ‫and more details to work with. There's my pro tip. 58 00:02:40,410 --> 00:02:42,615 ‫With any container, you can add a volume very 59 00:02:44,440 --> 00:02:46,669 ‫similar to how you did in Swarm and in Docker and Docker 60 00:02:46,670 --> 00:02:50,349 ‫Compose. You can just add a volume statement in 61 00:02:50,350 --> 00:02:53,349 ‫the template inside spec. If you think of the YAML file, 62 00:02:53,360 --> 00:02:55,759 ‫we can just put a volume in there like you would expect, 63 00:02:55,760 --> 00:02:57,524 ‫and the exact format and details are 64 00:02:58,990 --> 00:03:01,538 ‫in the resources. Unlike with Docker and Swarm where 65 00:03:02,620 --> 00:03:05,070 ‫the volume is with a container, in this case, it's 66 00:03:05,920 --> 00:03:09,909 ‫technically with the pod. It connects to each container, or 67 00:03:09,910 --> 00:03:11,373 ‫just one container, in the pod if you tell it to. 68 00:03:11,420 --> 00:03:15,249 ‫So, you're controlling it at the container level, but 69 00:03:15,250 --> 00:03:17,409 ‫it's persistence is with the pod level. There's a newer 70 00:03:17,410 --> 00:03:19,711 ‫feature that is persistent volumes. 71 00:03:20,030 --> 00:03:22,440 ‫That works with something else called a claim. 72 00:03:22,530 --> 00:03:25,659 ‫The interesting idea with this is 73 00:03:25,660 --> 00:03:28,370 ‫that you're using it, or you define it, outside 74 00:03:30,400 --> 00:03:33,095 ‫of the pods. You're basically creating that resource on 75 00:03:33,520 --> 00:03:35,823 ‫its own, and then you're making a claim against 76 00:03:37,750 --> 00:03:39,690 ‫that resource inside of your pod spec. 77 00:03:40,230 --> 00:03:42,835 ‫The reason this is more interesting is as Kubernetes 78 00:03:43,990 --> 00:03:46,450 ‫takes over the enterprise, you often have people taking 79 00:03:46,451 --> 00:03:49,659 ‫care of storage, often third-party storage, that isn't 80 00:03:49,660 --> 00:03:50,660 ‫the same team running Kubernetes. 81 00:03:51,150 --> 00:03:53,845 ‫They're going to be the ones involved with managing and 82 00:03:54,850 --> 00:03:56,460 ‫creating these persistent volumes. 83 00:03:57,500 --> 00:03:59,950 ‫Then it's the application deployers that are going 84 00:04:00,620 --> 00:04:01,620 ‫to say, hey I need a 85 00:04:03,610 --> 00:04:06,403 ‫volume of this type. So, I'm going to make a claim of SSD 86 00:04:06,610 --> 00:04:09,459 ‫or we may need RAM storage, or maybe I need 87 00:04:09,940 --> 00:04:11,410 ‫NFS, or whatever. That storage 88 00:04:13,360 --> 00:04:15,189 ‫will automatically be provided because the storage team 89 00:04:15,190 --> 00:04:16,335 ‫already set it up in Kubernetes. 90 00:04:16,930 --> 00:04:18,900 ‫That's kind of the idea around persistent volumes. 91 00:04:19,050 --> 00:04:21,745 ‫If you just need some simple storage on a single server 92 00:04:21,810 --> 00:04:25,239 ‫temporarily for the pod, then just use 93 00:04:25,240 --> 00:04:26,250 ‫the standard volumes attribute. 94 00:04:27,440 --> 00:04:28,560 ‫One last thing here is on 95 00:04:30,670 --> 00:04:32,974 ‫the creation of CSI plugins. In Kubernetes 96 00:04:33,700 --> 00:04:36,159 ‫history, anything that was third-party storage, whether 97 00:04:36,160 --> 00:04:38,953 ‫it's cloud storage or some third-party vendor storage, or 98 00:04:38,980 --> 00:04:41,185 ‫something custom, any of that stuff was added 99 00:04:42,070 --> 00:04:43,250 ‫in tree. 100 00:04:43,370 --> 00:04:45,281 ‫That means it was added to the binaries 101 00:04:46,390 --> 00:04:47,705 ‫of Kubernetes and shipped with Kubernetes. 102 00:04:48,400 --> 00:04:51,389 ‫That means Kubernetes came with Amazon and 103 00:04:51,390 --> 00:04:53,310 ‫Azure storage built right out-of-the-box. 104 00:04:53,780 --> 00:04:55,887 ‫That was pretty convenient, but it added so 105 00:04:56,920 --> 00:04:57,920 ‫many challenges. 106 00:04:59,110 --> 00:05:00,999 ‫Most of those were related to the fact that storage vendors were now contributing 107 00:05:01,000 --> 00:05:03,519 ‫code to the core of your system that you probably didn't 108 00:05:03,520 --> 00:05:06,279 ‫even need because you may only use one storage vendor, so 109 00:05:06,280 --> 00:05:07,280 ‫why have all of them? 110 00:05:07,660 --> 00:05:11,439 ‫Also, the storage vendors then had to control 111 00:05:11,500 --> 00:05:14,230 ‫their release cycles around the Kubernetes release cycle, 112 00:05:14,470 --> 00:05:15,910 ‫and it wasn't a very flexible model. 113 00:05:16,390 --> 00:05:18,759 ‫So, the industry came together, and like it did with 114 00:05:18,760 --> 00:05:22,029 ‫networking and with Dockerfiles and images themselves, 115 00:05:22,090 --> 00:05:25,240 ‫it created a standard. That standard is the CSI. 116 00:05:25,460 --> 00:05:27,699 ‫That stands for Container Storage Interface. 117 00:05:27,820 --> 00:05:30,940 ‫That is going to provide plugins now so that 118 00:05:31,030 --> 00:05:33,699 ‫any storage vendor can create a plugin that you would 119 00:05:33,700 --> 00:05:36,297 ‫install on all the nodes, and that would be different 120 00:05:36,670 --> 00:05:38,470 ‫based on the plugin and their instructions. 121 00:05:38,860 --> 00:05:42,519 ‫Then, they will operate on a standard API 122 00:05:42,700 --> 00:05:44,709 ‫that the CSI provides so that any of your 123 00:05:45,670 --> 00:05:48,880 ‫containers can use that plugin to get to their storage. 124 00:05:49,330 --> 00:05:51,670 ‫That's a much better, and more flexible, model. 125 00:05:51,680 --> 00:05:54,189 ‫That's kind of the future of Kubernetes, but it's still 126 00:05:54,190 --> 00:05:57,459 ‫pretty new. So often in examples, and even 127 00:05:57,460 --> 00:06:00,106 ‫your storage vendors may recommend, depending on their 128 00:06:00,130 --> 00:06:03,222 ‫maturity of CSI, that you use their traditional plugin, 129 00:06:03,790 --> 00:06:06,123 ‫which is built into Kubernetes and comes out-of-the-box.