Kubernetes and Container Orchestration 101 - Computer Stuff They Didn't Teach You #11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey friends i'm scott hanselman uh this is another episode of computer stuff that they didn't teach you um i would encourage you to go back if you just showed up at this video and you need make sure that you understand what i talked about in episode 8 containers so what explaining docker i talked about the point of a container and why a container is different than a virtual machine and then i would encourage you to check out episode 10 what is the cloud talk about the physical aspects of things with the context of the cloud so we're building concepts on top of each other this video is about kubernetes and kubernetes 101 there's lots of kubernetes videos out there lots of tutorials you can find kubernetes in five minutes and you can find take this kubernetes workshop for two weeks and do 80 hours of studying pick the one that makes you happy and the one that works for you i'm going to do my best in one take with no editing to explain to you how i think about container orchestration and explain to you why you should care if you should care and we'll do a lot of demos to try to understand that all right so again i want to remind you go back and check out the containers episode and check out the cloud episode to get an understanding of why containers are useful okay so if you have a physical machine whether it be a giant computer or a raspberry pi or you have a bunch of raspberry pi's a bunch of computers all working together the orchestration just like musical instruments in an orchestra this one plays and this one plays and they each have different responsibilities maybe this runs the shopping cart and this runs the product catalog and gosh we need four or three of these to run the product catalog and two of these to do caching and this one will do the shopping cart and we can make decisions about the responsibilities to make sure that our application works successfully that's the general idea around orchestration now in the past applications were put on a giant machine a big ball of mud style architecture which is good they call it sometimes a monolith sometimes that's the simplest thing you can do and if you want it to work better you want it to work faster you just turn the knob up to 11 you get more memory you get more hard drives you get more processors and you scale up um you can also scale out like i've done with this raspberry pi cluster and say well i don't want one machine i want 10 machines and they're all going to work well together kubernetes allows you to take containers which i showed before you just run them they do their thing they can come and go as they please and assign responsibilities sign requirements and build your own orchestra all right let's take a look at this just to remind us assuming that you are coming from the previous episode where we talked about docker i made a thing called my test and i named it latest and it was a container that i could just run the command line let's say that that was what they call a micro service maybe i would have web application number one and i want three of those in web 2 and web 3 and i want to have different ones what happens if an application crashes what if an application is using up too much memory what do we want to do that's where you go from a container to a container orchestrator now kubernetes introduces a bunch of confusing words and a bunch of confusing concepts i want to do the best i can to express those to you like this i'm going to basically just draw a picture and i'll do it in draw.io similar to the way that we did before so we'll start up here with kind of this main sometimes the people use the word master cluster the boss of kubernetes and then we're going to have nodes node is basically a worker machine now the thing that's interesting and where stuff gets complicated is that a worker machine could be physical or it could be virtual it's a unit of worker machine okay and that node inside of that node go and do this is what's called a pod i'm going to take these and i'm going to ask myself how to put the text at the top there i want to top align that that's not what i want i want the text at the top thank you inside of these is a pod now a pod just like if you are currently quarantined a pod is a group of people that you know and hang out with so you pod up with your friends or your family because you're hiding out from the virus let's say these are our friends we're going to put those containers together we're going to pod them up so they all stay together right here and then these folks here will just duplicate that'll be nice and easy oops here we go this main cluster talks to these other worker machines and coordinates this is just one example but the point here is that there is a conductor this cluster manager this conductor of our orchestra all right is talking to these worker machines and some worker machines may have one container and some may have three or five you don't know right we have no way of knowing because we're going to set up a series of rules that decides how these things come and go and that's the the flexibility the elasticity of these things for example it might be black friday on christmas and suddenly everyone wants to get into the shopping cart so then we're going to need to make lots and lots of containers and have them work together or maybe we're going to need multiple pods and make another whole worker machine so that we can scale you can scale up you can scale out we might have a miss a misbehaving container who keeps using up too much memory so when it fills up the memory we want to give it a good smack and then get a new fresh one that will do the right thing we can do all of those things remember this container just does its job comes and goes container orchestration is the act of building an application through the collaboration like a group project in school we're all going to know what our job is and we're all going to work together and try to do our job so let's write some stuff down and make sure that this is clear all righty so we've got a node as a worker we've got a pod is a group of containers now a pod and also refer to the containers the ip addresses that the containers need the the storage that those campaign containers are going to need to do their stuff and just other info and other information that is a thing there but the container is the unit of work is the unit of work it's the doer okay the doer oops i can only type when no one's looking but when people are here it's confusing so now i can name these pods and i could say well hey this is the front end pod and this is the back end pod and this is the one that does the shopping cart do all kinds of stuff like that what we did i went here i'm on windows you might be on a mac or on linux it doesn't matter i'm using wsl the windows subsystem for linux and i've installed docker desktop okay and docker desktop sets up a lot of things for us and makes our lives easier particularly on windows so in this example here we can see that there's no containers running i'm logged into docker you can do this on windows as well and docker desktop has this very nice enable kubernetes so feel free to go on google for how to install docker docker for windows and install kubernetes but ultimately you just set up wsl 2 install docker and check that box and wait a few minutes and you'll be in a pretty good spot and that's how i got this place right here now in this folder i've got a.net service a c c-sharp service i've got a node service i can go into my.net service if i wanted to and i could go and build that service from a a docker image very similar to what we did before so now i've done it and i've tagged it my.net service okay and i could then go and run it if i wanted to right run it on port 3000 and inside the container it's listening on port 80. and i would name it and i would run it and it would work great i could do the same thing for my node service remember i've got a.net service and a node service what if those are examples of services that i want to put into my kubernetes those containers i want to make them a part of this experience so that would mean making them containers within pods that live within my larger cluster my kubernetes cluster so the way kubernetes does things is a little bit confusing in my opinion uh some people think it's quite elegant i find it just to be a little bit confusing because they use a thing called yaml and yaml means yet another markup language so if you're familiar with json it's basically a a way to express name value pairs and hierarchical data so name value name value you can google and learn about this stuff but it's just a descriptor it's a hey computer i want things to look like this i want a pod i'm going to name it happy little pod and it's going to contain some containers the image is going to be my.net service now this one's very important this image poll policy says only go looking for it in my container registry or my public container registry or maybe a configured one if it's not present locally because i'm doing local development it's important that i keep that if not present because otherwise it'll try to find my.net service up in the cloud somewhere so we're going to be using the local one we listen on port 80 and this is an example of the power of kubernetes where i can go and say hey i don't want you to use more than this much cpu and this much memory and think about your limits and your requests i'm applying artificial constraints the container doesn't know that exists and that's super cool okay so kubernetes in practice is used for things like running these containers by creating pods i can make identical pods what i can do is i can run a thing called cube puddle sometimes people say cube control cube controller its cube cuddle is the way most people say it but regardless i'm going to run this command line here and i'm going to have it ask questions about my cluster cluster info you get this when you install kubernetes and it runs on docker so you can see here kubernetes is running on this local this is our local computer here on this port and it's got this cool api here i can go and look at it it'll probably tell me i'm forbidden to use it because i'm not an authorized user we'll talk a little bit about accessing that a little bit but what i want to do i'm going to take that yaml file that pod.net that's this one here we're going to make a pod in kubernetes and remember it's going to be one of these pods with a bunch of containers inside and if we ask to cuddle right now hey do you have any pods it's like no i don't i don't have any ponds we're going to say cube cuddle create and then we're going to say here's the file we'll say pod.net and then it says hey happy little pod got created we've got another one for our node application which is also a little application totally different language that's okay containers don't care i created both of those now i'm going to say get pods and you can see i've got two odds running asked for one got one here's how old they are they're just seconds old and they're doing their thing so they're running inside of pods and we have in this case just one container each that's interesting and ask some questions about these pods and see what it wants to tell me about them i can see an internal ip address that i can't access right now and see what it's running on docker that desktop or desktop is running that for me i can see that it it's not very old it has not restarted meaning it's not a sick pod that's having any challenges now i've only got one each of these but i might want to have more all we've done so far is just i told you we did in the docker video we made a container what if i wanted replicas i wanted clones of my containers i want to add three of them i'm going to make a happy little replica set for my my little application here with three replicas and i want three different copies of the.net service in there so this is a descriptor of what i want this isn't a programming language it's a declaration it's a bill of lading it's a give me this i'm going to say let's go and create we can also say apply apply is interesting because create says do this make a new one and apply says i don't know if it exists or not i just want to make sure that it gets done so either make it if you have to or change it doesn't matter here we're going to make our replica set now when i say odds i'm going to see the beginning of some things here but if i go and say describe not just get but i want lots of information i'm going to say describe this little replica set talk to me about this you know look at that three replicas desired recurrent all listening together suddenly i've done this i've done the eq the software equivalent of this maybe not the full the full six but i made three i made three dot net containers they don't know that they got created this way that's about the separation of responsibilities containers do their jobs do their jobs and they don't restart themselves they don't even know who they're talking to they don't trust anyone they are just you know kittens doing their thing here though we're starting to bring that herd together the herd of cats and get the orchestrator doing that work and that's really interesting you see those other pods we made about two minutes ago are still doing their job in fact that describe command is really interesting because i can go and say describe pod you could ask questions of the pods themselves see what's going on inside there hey there we go i'm going to make this a little bit a little bit smaller we've got our odd and see who it's controlled by who the container is how much limits it has and find out information now i'm doing this from the command line there's lots of cool dashboards and graphical interfaces and things that'll let you figure out what's going on the simple thing that you'll see in docker in the docker for windows is just the running pods but these have goofy names and long these are all generated names this tells me a bunch of stuff is running but i'll use the cube cuddle command line or i could install optionally the kubernetes dashboard would be a way to see that now it's a little confusing when you're doing uh this stuff particularly in kubernetes that the ip addresses get really confusing i'm going to have to do a video on ip addresses because that's not the ip address of my computer we have to understand software-based networking and we see that it's not exposed to the outside so i don't really have a way to talk to these yet and this is a a matter of this kubernetes deployment this cluster as kind of a dotted line around it like this okay i went like that can i make a dotted line do this let's change its style let's see if we can do that here you go the dotted line so it's not real and they all live inside a computer within a computer it's as if your computer had one of these inside and i can't get to any of these they're not automatically exposed to the outside if i want to see these i need to punch a hole in i need to draw a circle around these or a square and i need to say you know these pods are a service or these pods are a service so i can tag them i can name them i can say shopping cart front end back end i can say well those are on this port and those are on that port i could even name them just like you have dns domain name service on the internet and i can go hanselman.com you can have internal dns managed by kubernetes so i can say http slash shopping cart doesn't mean anything to the outside internet but internally it would allow me to write code that could say talk to this api talk to that programming interface and get information from that shopping cart from that product catalog internally i don't have to think about ip addresses i don't have to put anything in configuration i can just say i want to talk to the shopping cart and maybe there's one or maybe there's five the configuration manages that so i can change the shape of my service i can load balance it and expose it in any way that i want so right now what do we have we have this service and these pods but if i was going to say do we have any deployments do we have any sense of how these services should be expressed the only service we have is kubernetes itself so there's a couple ways i can do that i can make another yaml file and express a service what i'm going to do is i'm going to just expose our little hello world oops as a node port what i'm actually going to do [Music] i skipped a step here we go i'm going to make a deployment i'm going to say make this application consist of these containers and then i'm going to expose its port to the outside so we'll say you control a cube cuddle a lot of controversy about how people want their things referred to i don't really mind you call it whatever makes you happy there we go we just said hey make this service notice that that one said unchanged because i did it fast there we go and then let's see our deployments aha now we're talking that's interesting okay so let's do our describe remember that trick we describe this and we go describe happy little hello world i think we have to put the word deployment in front there we go this is telling me about this deployment so i could have dev test staging i could have my practice one and the one the developers used the one we use for production you can decide these things and again does our service know about any of this no suddenly i'm just playing my instrument doing the best i can as part of a larger orchestra and that's why we call these things uh container orchestrators i think about it as herding cats so you can think about it as herding or managing or orchestrating inducting it's totally up to you but the concepts are the same so now we've got this but now back when i jumped the gun remember when i said i'm going to expose that deployment and make that now available to the outside well that's interesting i know i have a service if i say cube cuddle get service now look this is the larger kubernetes cluster which is interesting because kubernetes itself is just a bunch of containers what's funny about this is that if you do this call cube cuddle get all look at that what i see my service my deployment but what's all this other stuff well i live in the default my container lives in the default namespace kubernetes is hiding stuff from me what is kubernetes it's a bunch of other containers that are doing a bunch of other work all together it's not one orchestrator it's not one conductor it's a whole group of them and they all have different responsibilities they may have responsibilities for storage for networking for dns lookup it's all different things so if my container goes away there's someone inside of kubernetes who's responsible to bring me back to life or make a clone and make sure that i keep running the the dashboard if you were to install the kubernetes dashboard that itself would be an application would be a container would be a pod that you would fire up and be able to see but i don't see that i just say get all i don't need to worry about that stuff so kubernetes is a series of containers that manages all this kind of stuff all we've done is we've made our happy little service we've exposed it out to the outside world we've done a little port mapping port mapping is interesting because my container might be listening on port 80 and then my pod might be listening and i need to make sure that my traffic my tcp traffic flows smoothly as it gets routed through from place to place you do have to think about the ins and out supports so where port 31914 on the inside on the outside and port 80 on the inside there's a lot of networking you have to think about so be prepared for that one of the things is i might want to access my ports we actually haven't seen our application run yet have we well kubernetes has an api that you can access but in order to do it you have to tell it to proxy that traffic to allow that traffic so i'd love to get on localhost 8001 here and see that traffic i need to go and type cuddle proxy and now it's going to be listening when i go like this now i see all the different things all the apis ask questions of kubernetes like the version i see my version my information here and i see all of my pods when i was typing cube cuddle let me actually do a show a little trick i'm using the windows terminal here i'm going to go and type in lit pane vertical let me make another pane over here we're going to keep our proxy running and over here on windows and the windows terminal we're going to say get pods where does that information come from that information comes from here that's cool here's our pod here's our app all expressed in a nice javascript json kind of an api i can look at my little pods what were my pods names i think we had little.netpod here we go see what it's doing look at that but we haven't actually seen the app run yet so i can write i can say slash proxy and look hey i'm a.net core app doing some work now that app is not running on port 8001. what's happening is when we said tube cuddle proxy we punched a hole in our reality here we took this square that we've got around our entire kubernetes what we did is we said hey i need access this whole this whole opaque square that represents my kubernetes installation i need you to go and punch a hole in the top and i want to make sure that i can access it via port 8001 and we're proxying the traffic that means you talk on port 8001 and it says all right i'll go and i'll tell i'll tell him for you i'm acting as your proxy you tell me i'll tell him it'll be transparent trust me i won't change the traffic or anything so now can i do happy little.net pod happy little node pod here's a node app doing some work so i've got a node pod i've got a dot net pod you're just hanging out cats and dogs living together mass hysteria but now what could i do could i maybe expose that let's go ahead and split our panes again and we'll do this time a horizontal split this is the windows terminal you can get this in the windows store and i'm hitting ctrl shift p to bring up that pane that's allowing me to change things around i'll do videos on that if you're interested so now i'm going to type tube cuddle and i'm going to say hey can we temporarily punch a hole deeper rather than a proxy i really want access to that that service i want to see exactly what's going on let's go ahead and do this let's put it on port 81 locally and we'll forward it to port 80 on the inside that'll be temporary and look it actually says that orbiting from it'll hang there but now we're on localhost so now i should be able to go localhost localhost 81 now i can see that.net core app on port 81. if i hit control c and it goes away now we've lost port 81. there's a lot of interesting networking going on when you're doing this kind of work and again you can see these things by asking questions of kubernetes like cluster info and you can get the kubernetes dashboard and see different ways to express this stuff the most interesting controls the most interesting uh pardon me uh commands in kubernetes in my opinion when you're messing with cuddle are describe that's one and then explain and then you've been seeing me this whole time use get to get information about these things and you'll recall we were getting information about pods about go back here about nodes about clusters there's other things in kubernetes that i haven't had time talk about because this is only a few minute video all of these things uh are just vocabulary words for you to lose to learn but the fundamentals of kubernetes are that it runs containers it manages their lifetime and their life cycle and it is doing its work by creating pods typically you have one container per pod but you can have multiple ones you can then deploy a pod to replace another one so you can have rolling deployment upgrades where version one goes away version two stays you can slowly drain traffic off of a pod and bring traffic up on another you have you can set up traffic and networking any way that you want so that you can have different pods talk to each other now this is a lot this is a lot of information but the fundamentals are the same you run a container it does one job and it does it well then you run n number of containers physical virtual windows linux it doesn't matter you give them constraints you give them memory you get them cpu you give them storage you set up networking around them you make sure that they can reach each other and you do the best you can the things that are challenging about kubernetes is a lot of vocabulary it's challenging to remember how yaml the yet another markup language works there's a lot of text going on should you learn kubernetes can't hurt i think that in the future a lot of this will be hidden from you and you won't have to worry about it you'll just deploy your app and your app will just work but it's a really really interesting technology that a lot of people are really excited about right now and it sits on top of the concepts that we've been learning about here i think that this is a pretty good episode of computer stuff that they never taught you please subscribe and you can help me out by telling your friends about these and other episodes
Info
Channel: Scott Hanselman
Views: 68,116
Rating: undefined out of 5
Keywords:
Id: 3RTvoI-A7UQ
Channel Id: undefined
Length: 31min 21sec (1881 seconds)
Published: Sat Sep 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.