K3d - How to run Kubernetes cluster locally using Rancher K3s

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this might be the best way to run a local kubernetes cluster or a temporary kubernetes cluster meant for testing maybe it's not it really depends on a use case we'll discuss that at the very end for now let's see what that something is and how we can use it and go through some demo discuss the pros and cons and then make a decision should you use this to run your local kubernetes cluster today we are going to discuss k3s or actually we are not going to talk much about k3s we are going to talk about k3d which is k3s running in a docker container or in a container so what is k3s let's start from there k3s is a lightweight very very lightweight kubernetes distribution made by rancher and rancher is an awesome company why is it important for k3s to be lightweight the answer lies in the destination in the places where it is typically running and those places are usually iot or internet of things and edge computing and those devices do not have as much power as typical servers so it is extremely important that k3sc is lightweight and it indeed is it is almost full kubernetes functionality but shrinked to a size that makes sense for devices like that and that might be very important when we are talking about local kubernetes clusters because you probably do not want to run a local kubernetes cluster that will eat eight gigabytes of your memory before it even starts doing something or before you even deploy your application so being lightweight is important for iot and edge computing but it might be very important for your laptop as well so we got k3d which is a variation of k3 sorry to be more precise it is k3s running in a container and then we can run those containers locally to create a cluster that could be one node or more nodes we can have one cluster more clusters and so on and so forth we're going to see that in action in a second but before we proceed let me explain why am i talking about k3d now and not maybe half a year ago and the reason why i'm talking about it right now is because recently few months ago only it got a config file and for me defining a cluster doesn't matter whether it's a local cluster or remote cluster or whatever it is i need a config file i do not want to remember all the arguments and stuff like that so k3d got the config file i think somewhere in january or february january i think in 2021 and now that becomes very very interesting solution and potentially a better solution than the one i showed you a while ago the one about kind if you haven't seen the video about kind stop this one go the link is above my head check it out that was my recommendation for running local kubernetes clusters until now or maybe it will continue being my recommendation we don't know yet we're going to see that at the end for now check out kind if you didn't because it's good to compare it with k3d it has a lot of similarities but some things are different anyways check it out and then come back here are you back do you understand how kind works now let's go into the hands-on part and explore k3d in 20 minutes or less and once we do that we're going to discuss it and we're going to choose whether you will use it or not and if you will use it whether it will cover all your needs or some of your needs whether it's only food we'll discuss things at the end for now let's go into the hands-on part and see how that thing works let's start with the setup what do you need to run k3s on your laptop or somewhere else or to be more precise what do you need to run k3d which packages k3s and it's fairly simple you need two things you need the ability to run containers if you're using mac os or windows you can use docker desktop if you're using linux or windows with wsl then you can use just docker without desktop anyways you need the ability to run containers and probably the easiest way to run containers locally or in temporary clusters is with docker it's not a good option for real kubernetes clusters actually it's a horrible option for running containers in kubernetes clusters especially production if you don't understand why i'm saying that check out the canico video it's above anyways for local usage and for temporary clusters docker is a great solution to run containers and that's what you need now apart from docker you need k3d cli you can install it and the link instructions how to install the cli and all the other commands that i will run today is in the description of this video so go to the description of this video and you will find the gist with all the commands all my videos that i made in last i don't know how many months container just this one is no exception now let's create the first cluster with k3d and see how that works so i'm going to execute k3d cluster create and i'm going to give it some name like uh my cluster right and let's see how much it takes to create a cluster right uh probably a couple of minutes is that what you're guessing or maybe a minute no no look look at it it's coming it's coming it's over there almost there yes that's it the cluster was created it's finished and it took i don't know how much it took probably like five seconds ten seconds it's lightning fast is the fastest thing i've ever seen at least when running local kubernetes cluster that's a good thing now to confirm that this is a cluster running as a container we can do docker container ls we can see that there are two containers over there one the latter one is k3s that's actually the cluster and there is a proxy over here the first container at least in my case which will proxy the requests entering into docker and going into that cluster it will just do the proxy think of it as external load balancer thingy something similar to it now the good thing about this is that ingress is already baked in it is using traffic which might be a good thing or a bad thing we are going to discuss that later but for now having a proxy and ingress capabilities baked into local kubernetes cluster is awesome uh because hey we need to access those things and pour forward is just horrible horrible horrible command which everybody uses and i don't really understand why now let's take a look at the pots what did we get cube cattle get pods dash a and we can see the system is running right for now just think of this as being everything that you really need to run your kubernetes cluster or it might not be everything you need we'll discuss it later and similarly we can do cube cattle get notes and we can see that there is only one node which is good for majority of us in majority of cases but it might not be what we always need sometimes we might need more nodes or sometimes we might need more clusters so let's start with the latter case we can create any number of clusters and the limitation of our resources and you know how much memory cpu you have in your machine but since this is lightweight more lightweight than anything you will be able to squeeze more clusters than you would be able to do with kind or especially with mini cube and so on and so forth so if you would like to create the second cluster we could execute the same command or almost the same command so let's do it k3d a cluster create and then i'm going to how am i going to call it another cluster that's creative right and we can specify a different image we can say hey for this cluster i do not want the default kubernetes version i want to be more specific so that it is closer to what i might be running in production so we can specify an image and that image will be launcher and then k3 s and we're going to choose let's say kubernetes 120 right that would be version 120 and i think that this is the latest one k3 s1 you will need to check the images to see what exact version you want i did that in advance and then we create a second cluster just like that and look how fast this time it will take a bit more time because it needs to pull the images and there it goes it pulled the image that's only the first time and now it creates a cluster it should take five seconds or something like that and there we are it's finished i mean it's trying to find the ip and now it is finished that's fast that's lightning fast and i like speed i do not want to waste my time i like things to happen within seconds or within hours if it's within hours then at least i can go to cnn or watch a movie or something like that the worst case scenario is when it takes 15 minutes and then you cannot do something interesting and you get bored to that and now if we list the containers docker container ls we can see that we have four containers now two containers that represent two clusters and two containers that represent proxies into those two clusters but there's more to it we might want to create a configuration file but before we do that let's see how we can delete those two clusters and start over in a slightly better way so the command is k3d cluster delete and then the name what is the name my cluster i think was the first one there we are deleted within a second it's extremely fast and then let's do the same thing for the second cluster kt k3d cluster delete and the second name it was another cluster i think there we are it's gone it disappeared and my resources are free for something else in case i need them we can execute commands like the ones i showed you create a cluster when we need it uh destroy the cluster when we don't but a better way to do things is to create a config file store it in a repository of the project we are working on and then we create a cluster depending on a configuration file so cluster is always as we want it to be without trying to figure out what are the additional arguments we might need to specify or we might not need to specify anyways let's see how we can use the configuration file and to make it more interesting we're going to create a bigger cluster with more nodes and a few other things so let's explore that for a second and that configuration file is in a git repository uh and i'm going to clone it https github.com and what is the name of the repo i think it's sketchy demo.kit there we are we got the repository i'm going to go there excellent now let's take a look at the config file i'm going to use today and it says hey you know what this is a simple type of cluster there will be more complicated later on i think that this is the only one currently available the api version the name of the cluster is going to be called my cluster the image which effectively says which version of kubernetes we want to run in this cluster so that you don't need to remember dash image this and that how many servers do we want three servers this is going to be a bigger cluster and three agents servers are effectively control planes and agents are working nodes and the parts we want to open 8080 on both sides we're going to enable load balancer over there and i have a few other options that i commented we're not going to go through them right now i just want to show you that there could be additional options and options and options right this particular one that is commented would be in case we do not want to use traffic as ingress and we are going to discuss that later so now to create a cluster the command would be k3d cluster create and then we say config and the path to the config file which is this one there we are it should be five seconds four seconds six seconds i don't know how long it takes it shouldn't take long actually it will take a bit longer than usual because it needs to create six nodes three four control plane three four working notes and while we're waiting why don't you subscribe to this channel and click the like button if you got this part in a video you probably like it you would give up earlier so click the like button and subscribe if you haven't already slow i'm disappointed you'll see it's still faster than using any other type to create multi-node clusters but it takes a while longer so let's fast forward to the end of the process there we are we got the cluster we can do cube custom get notes and see what's inside of that cluster or how many nodes do we have and we can see here that it's six nodes three are for control plane and then the lcd and master actually it's misleading it's not k3s is not using cd but we're going to discuss that later as well anyways three for uh control plane and three for worker nodes and that's our cluster in this specific case right and now i do not need to worry about how big of a cluster i should create what she should have what it shouldn't i can just put a config file yaml file in each repository i work with and then create whatever is defined there now to be honest that's not specific to k3d you can do the same thing with kind you can do the same thing with the mini cube but still it's awesome and k3d didn't have it until few months ago so that's why i didn't use it until recently finally let's confirm that we can actually use this cluster not only create it and i'm going to deploy something with cube catal apply file name and then the address is k3s this is the directory it contains definitions that i prepared the small demo and you see it created it and let's see whether it works and to see whether it works we can use localhost because this is going to docker desktop and it is being forwarded to the cluster let's see whether it works so the address is local host without port since on 480 and there we are right this is the application that was just deployed in this newly created cluster it all works it's all peachy and it's lightning fast i must repeat this over and over and over again this is the fastest local kubernetes cluster or kubernetes cluster meant for temporary testing purposes or something like that now i spoke a lot about speed let's put that to the test is it really that fast is it faster than kind which i which i told you to use only a few videos ago let's do a speed comparison but before we do that let me delete the cluster we just created and we're going to start over and do a speed test and see who is faster kind or k3d both of them are very similar oh i made the typo k3d cluster delete my cluster there we are okay speed test is coming next we're going to test a couple of combinations this will be speed test between kind and k3d they serve similar if not the same purpose they are very similar in architecture they are all kubernetes clusters running inside containers and we're going to see who is faster because let me tell you in advance most of the other things no actually that's not true there are differences but let's see about speed who is the fastest one and we're going to start with k3d actually let me explain we're going to start with a single node cluster and then we're going to see whether multi-node cluster is any different animal a couple of tests anyways to create a cluster with k3d we're going to do k2d cluster create and then my cluster and we i'm going to time this you will see a timer running around that will show how fast it is now it is pulling the image this might be the thing that takes the longest it's there creating load balancer pulling image this is like being a commentator of an honor soccer match or baseball match or whatever you're watching but anyways uh i will not comment much on the time right now because in post-production i don't know how much exactly it took but there it is that's how much it takes to create a clustering k3d i think it's around 20 30 seconds something like that now let's destroy it and see how we can do the same thing with the kind k3d cluster delete my cluster and it's gone now let's see how much time it takes to create the cluster with kind and the command is kind create cluster named my cluster let's call it the same as the previous one and this will i did it before i already know the results it will take a while so i'm going to fast forward to the end of the process [Music] now i cannot say how much exactly it took because i did not time it but i will put you should see the timing on the top of both k3d and kind but even without knowing exact timing k3d was faster than kind now i wanted to do a speed comparison with creating a multi-node cluster but i will not bore you with that because i know the results in advance kind is much slower than k3d with the single node cluster and if we increase the number of nodes it just gets worse it is comparatively faster and faster the more nodes we have so if speed matters and it should because you want to create a cluster like this you don't want to wait until those things happen k3d is a winner here's what's going on k3s not k3d we're going to get to k3d later k3s removed all the things that are not necessarily necessary rancher the the company behind or the community behind the k3s removed legacy stuff from kubernetes they removed also alpha releases of stuff non-default things in three plugins and so on and so forth so they shrinked kubernetes drastically by removing things that you're most likely not using but but remember that i said most likely that will become important later for now let's say that you're probably not using those things also they replaced some kubernetes components with lighter versions of the same things for example instead of using fcd which is or in almost every kubernetes cluster it is using l-sql light and all those things are important if you're running in iot or on the edge because you want it to be as small as possible because those things do not have a lot of memory in cpu and whatsoever and that's what makes k3d awesome because k3d is k3s in a container and it's absolutely awesome not to have to waste more memory and cpu than necessary on our laptops because we want to save the resources on our laptops for other things whatever those other things are but hey it would be nice to run a kubernetes cluster that base no resources that is tiny tiny tiny so resource usage and speed of k3d is a huge bonus it's a huge benefit that makes it better than kind and definitely better than docker desktop kubernetes mode and infinitely better than mini cube it is fast and it is tiny but that comes at the cost which for you might or might not be important and that cost the price is kubernetes compliance i mean k3s is compliant with most of the things or everything that you are using probably but it is not a fully compliant kubernetes cluster that is doing everything that kubernetes does it's just doing most of the things that everybody needs so if you need a kubernetes cluster running locally or temporary test environments and that cluster to be compliant or closer to be compliant with whatever you're running in production kind is a better option k3d might not be the best option but for majority of us me included most of the time not always most of the time that does not matter because locally i want to run my application and my application is most of the time working quite well in k3d and at the same time i foster and i say resources but if you want to test let's say moving from one kubernetes version to another locally or in a temporary environment you might want to use kind for that if you want to be closer to production for everything else k3d is a better option as long as you're not using legacy resources and alpha releases but you shouldn't be using alpha releases anyways except if it's try it out and see how it works so is k3d better than minicube and docker desktop the you know the one with kubernetes enabled yes definitely it is a better option to run kubernetes locally and it is a better option for the same reasons why kind is a better option so if k3d and kind are both better than mini cube and docker desktop probably for running clusters locally then the question is which one should use of the two and i say k3d because it's faster it uses less resources except if you're using some things that are not available in k2s so try it out write out with your applications if everything works fine you're golden if it doesn't if you're using alpha release of something if you're on the cutting edge of kubernetes then kind might be a better option but there is a thing you should be aware of k3d uses traffic and that might or might not be a problem if you're using ingress without specifying which interest you want then that will work if you're using some specific english if you need nginx ingress and you absolutely need it i mean most people don't you don't care locally whether and anyways if you need a specific ingress you need to disable traffic and install the english you need otherwise for majority of people if you just want to see traffic coming in then traffic should be okay as long as your manifests are not specifying explicitly that it needs to be some specific english controller that's it thank you for watching you know what to do hit the like button subscribe to the channel do all the stuff that you normally do in youtube keep sending me your suggestions k3d was suggested in a ton of comments that's why i made this video so keep your suggestions coming and i will keep making videos based on your suggestions that's more fun for me and for you than me trying to figure out what might be the subject you're interested in so keep them coming see you next time cheers
Info
Channel: DevOps Toolkit
Views: 32,905
Rating: undefined out of 5
Keywords: k3d, k3s, k8s, local cluster, kubernetes, docker, testing cluster, local kuberentes cluster, testing kubernetes cluster, viktor farcic, devops toolkit, devops, toolkit, k3d kubernetes, k3d tutorial, k3d k3s, review, viktor farcic youtube, devops toolkit series, devops tools, docker and kubernetes, local kubernetes cluster, setup local kubernetes cluster
Id: mCesuGk-Fks
Channel Id: undefined
Length: 24min 4sec (1444 seconds)
Published: Tue Apr 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.