How to build your own Raspberry Pi Kubernetes Cluster

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back everybody today on learn Linux TV we are going to take a look at how to create your very own kubernetes cluster using the Raspberry Pi platform so go ahead and click that like button click that subscribe button and we'll dive right in [Music] okay now before we do get started I want to address an elephant in the room that you guys are probably wondering about this guy right here what the heck is this well I wanted to show it off in the video it's called a cloud lit case which basically allows you to dock seven raspberry pi units in one case it even has room for a switch on the bottom now this case is definitely not required but I wanted to show it to you guys in case you wanted some inspiration on something that you might want to purchase so that you can display your raspberry PI's in a very cool way now you definitely don't need something like this in order to build a kubernetes cluster but if you do want to make it look cool this is just one idea that you could go along with and if I searched ebay and amazon and things like that you might find other solutions as well but as far as what you do actually need you will need at least two raspberry pi units I recommend the Raspberry Pi 4 they are more powerful than the ones that have come before so there's no reason to buy a 3 or below I do recommend the Raspberry Pi for the 4 gig model is great if you can get that one the 2 gig model is a good minimum if you can only get that but the Raspberry Pi 4 with 4 gigabytes of RAM is the best option you will also need an SD card for each Raspberry Pi and of course a power cord for each one the Raspberry Pi 4 takes a very specific power supply without getting into too much detail there's a design flaw that basically means it won't work with your average USBC charger but as long as you buy an official Raspberry Pi 4 charger you should have no problems whatsoever now I mentioned two Raspberry Pi units at least you can have five you could have 10 you can have a hundred but if you have a hundred please show me a picture I really want to see it but basically the only requirement is that you have at least two because you need one as the master and then you need one worker and you can have additional worker nodes and even add even more additional worker nodes as you grow which is what makes this platform extremely scalable now what you'll also need is to download the Buster Lite edition of raspbian raspbian is the most popular Linux distribution available for the Raspberry Pi platform and the Buster Lite edition what makes that different is that it doesn't include a graphical user interface at all which works well for us because we want to leave as many system resources available to the kubernetes software as we possibly can it just basically has less overhead you can use the tool etcher to flash that downloaded image onto your SD card you'll do that on each one and then once you're all set we'll go ahead and continue if you don't already know how to use at your I have a video on my channel that will show you that process now I'm going to grab my laptop I'll switch the camera over to that and I'm going to show you how to prepare your raspbian SD cards for use with kubernetes so we'll go ahead and get started so here on the terminal I'm going to show you a couple of quick things that are going to make this process a lot easier so first of all I'll do DF - H and that's going to show me the various storage volumes that I have attached to my computer LSB LK also works as well now you should see boot and route FS has two different mount points if you plug in your USB SD card reader or you put the SD card in your computer now again this is assuming you've already used etcher to create your SD cards when you insert it back into your computer you should have these mount points now first of all we're going to let's do LSB okay we're gonna CD into run media username and then boot and this can vary from one distribution to another if you're doing this from Linux so just go ahead and use whatever path shows the boot directory I'll press ENTER and now I am in that directory what I want to do is touch SSH just like that now what that's going to do this is going to create a file called SSH it's going to be 0 bytes what this will do is cause the SSH service to be enabled the first time you start your Raspberry Pi with that SD card so I recommend that you do this on each of them now I'm going to go back to my home directory so there's another change that I recommend you make that will make this process easier so again I'll do LSB ok and what I want to do is go ahead and CD into the directory route FS I'm going to basically paste the whole path I'll CD into there and then what you want to do is CD space at C make sure you don't put a forward slash here you want to leave the forward slash out press ENTER and we are going to edit a file but we need sudo permissions we can use the Nano text editor and the file we want to edit is hostname I'll put in my pseudo password here and the default hostname for the Raspberry Pi image is well Raspberry Pi and this is going to be a little confusing because if you were to insert your SD cards into all of your raspberry PI's and turn them on all at the same time they will all be named the same so let's go ahead and rename them before we turn them on so this is the first one right here I'm going to name it k8s master just like that and if it was a worker node you could do something like worker 0 1 or whatever naming convention you want but basically you want to change the name on each SD card so when the raspberry PI's boot and you look at your DHCP server you'll know immediately which ones are which when you go to connect to them now to make mine very obvious I'm going to have this naming scheme right here I'll just put LL TV in the name and then I'll save the file and then close out now there's one more file we want to edit so again sudo nano and I am in the Etsy directory so what I want to do is edit hosts and you can see on the last line we have that same default name we're basically going to just change that to match whatever naming convention we decided to go along with so I'll go ahead and make that the same in my case and again ctrl o enter ctrl X so in this point I can just basically CD back to the home directory because I can't unmount the SD card when I am inside the SD card on the current working directory and to keep it simple we could simply open a file manager window here and we could just make sure that we eject everything and then what you'll do is repeat this process on each of your other SD cards go ahead and name them in both of those same files and then unmount them when you're done to ensure that each SD card has its own name this video is proudly sponsored by Linode I've trusted Linode for over two and a half years as my infrastructure provider along the way I've used them for all sorts of things like my web server for example the wiki for this youtube channel is also hosted on it and i also use it for quite a few of the tutorials that you've enjoyed on my channel recently I recommend Linode because it's simple to use has affordable capped pricing that just makes sense and reliable 24 by 7 support available by phone or support ticket if you're a linux power user your server customization options are all but limitless even if you are just starting to learn you can use Linode growing list of one-click installations to easily get a site app or service up and running in the cloud to get $20 in credit toward your new Linode account use promo code learn linux 19 @ sign up or just visit the URL that you see on your screen right now I'd like to give a special thank you to Linode for their support of my channel definitely go ahead and check them out and now let's get back to the video okay so after you do all that you'll basically just insert the SD cards into your Raspberry Pi units plug in an ethernet cable power them on then after some time you should see them in your router under the DHCP table so here's mine for example if I scroll down now the names of my raspberry pi units are going to be overridden in DHCP because I have a static lease for those but basically you should see the host name we can see a couple of mine here and the three that I am going to set up are each online so basically in your case you should have whatever name you gave your raspberry pi units listed in the DHCP server address table of your router and that will give you the IP address that those units were assigned you can see mine right here on the left so then what you do is you go ahead and just copy one of the IP addresses so I'll just start with the master go ahead and copy that now in the terminal you could do SSH pi at and then paste the IP address right here I'll say yes to accept the default password for Raspberry Pi installations is raspberry we can see the name that I have chosen for the master is right here so I'll open a new tab go back to the DHCP table go ahead and copy this IP right here and again my names are only showing different because I override that in my DHCP server I'm sure yours will be a lot easier basically again just look for the name back in the terminal I'll do an SSH pie at paste the IP in there raspberry for the password now I am connected to the first worker node and I'll do a new tab yet again and then I'll copy the IP address again you know the drill and now I have a shell session open for the master the first worker node and the second worker note if you have more than two then of course you'll just repeat this process for each of those now most of the commands that I'm going to give you will need to be run on each of the raspberry PI's if something only needs to be run on a particular raspberry pi I will let you know now first of all what we want to do is go ahead and update the system so we could do sudo apt update and percent and person sudo apt dist upgrade what this is going to do is it's going to resynchronize with the package repositories and if this command here is successful then it's going to chain into the second command which the dist upgrade will actually install the updated packages so I'm going to go ahead and copy this I'm going to paste this command on each I press ENTER and then press ENTER and enter as you can see in my case it wants to update 67 packages and it will require seven new ones so I'll press ENTER to confirm and I will do that on each of these tabs and I will be right back as soon as this is complete if we see a message like this we can simply type Q to break out of that message and let the process continue all right so all the packages are up to date on this one at least let's check the others and it looks like they are all complete as well now that we've installed all of the updates we actually do need to reboot each of these notes but we're not going to do that just yet what we're going to do right now is we need to edit a text file and this is the text file we need to edit right here again we need to do this on each of the raspberry pi machines here which is press ENTER on each one so now we should have the same file open on each Raspberry Pi now what we need to do is go to the end of this line right here press space and then we need to paste this right here which you look like it kind of wrapped a little bit here I'm going to press enter so you can see what I just pasted there at the end but you don't press Enter it all needs to be on the same line go ahead and pause the video if you need to I have a wiki article linked below that will have a list of all the commands in case you need to copy and paste them but again this needs to be on the same line I just wanted you to be able to see it so it's basically going to look like this you have root weight space and then you have the start of the new options that I have added then you do ctrl o and then enter to save it and then ctrl X to exit out and then you just repeat on each one of your other nodes now each of those nodes should have that new configuration added we basically just needed to make some secret changes now a few more things before we reboot there's one problem we need to solve and that problem is swap is enabled if you do free - M which shows you the available memory that's free we actually do have some swap space here only 99 megabytes in my case but you actually should not have swap at all whatsoever we need to disable that and in fact if we don't it'll actually complain when we go to install kubernetes so I'll clear the screen and there's a couple commands we will run to solve that so it's this one right here this command will actually turn swap off and now if I do free - M we have zeros right here across the board that means swap is turned off unfortunately when we reboot the pi swap will be re-enabled again we'll get to that point in a moment we'll fix that too but I'm going to run that command on each easy-peasy so to make sure that the swap file doesn't ever return couple commands to run but first of all we're going to run this one which will remove the swap file completely easy enough and to be very sure the swap file can't come back we're going to completely nuke it with this command right here we're actually going to remove the package that creates the swap file in the first place so that's going to remove a package and again same thing on each you alright alright so now that the swap file is disabled we still need to reboot because we did run some updates here so we can run sudo reboot on each one of these nodes here go ahead and give them a restart and then basically we just wait a few minutes for those to come back up depending on the speed of your SD card shouldn't take more than a minute or two at the most so just give it a moment and we will try to SSH back into those instances okay let's see if enough time has passed I'll press the uparrow basically I'm going to recall the SSH command that we use to connect to the instances in the first place so enter default password again of raspberry and we'll repeat on each one of the other tabs here and we should be connected to each node yet again and we can confirm that they actually did restart by issuing the uptime command and we can see that it actually did reboot because the uptime is about a minute and now we can go ahead and install docker I'll paste the command right here you can go ahead and pause the screen if you need to but again I have all the commands in the wiki article linked in the description below and since we need to run this on each node I'll go ahead and paste it on those as well and then press Enter so now docker should be installed we can confirm by looking at the other tabs and sure enough it looks successful to me so next what you could do is copy this command right here this will add your user to the docker group if you created another user you'll need to adjust the user name accordingly but if you are following along with me you should be able to copy that command as is go ahead and paste that in press ENTER and then disconnect so I just did ctrl D to logout I'll do the same thing here ctrl D or type exit and then enter to logout and then also on this one as well and now we just basically go back in and we are back into our instances and the reason why we did that is because we wanted to make the changes to our groups take effect we wanted the PI user to be a member of the docker group and we need to log out and login for that to take effect so now what we need to do is edit a text file on each note I'll go ahead and paste the command right here so sudu because we need root privileges we can use Nano you could use whatever text editor you want and it's Etsy docker daemon JSON and in my case this file is going to come up as an actual file with contents in it but in your case it's most likely going to be empty so I'll press Enter and here's the contents of that file now go ahead and pause the screen if you need to or you can just grab the contents of this file in the link in the description below then you can do ctrl o and then enter to save it ctrl X to exit out and again do that on each of your nodes now on my end I already took care of it and I have added that file to each so now all that's left is to do one more reboot I'll do that on each machine and then give them a moment to come back up all right back into each node we can go ahead and continue now again what I'm about to show you it needs to be done on each node so I'll go ahead and paste the command right here so what we're doing right here is we are editing yet another text file and basically what we're doing is we are adding the kubernetes repository to each raspberry pi you and now we have the same file open in each of these and then what we're going to do is go ahead and paste in this line right here this is the repository URL for installing kubernetes and you can ignore the fact that it says any 'l right here this is the correct repository for the raspberry pi so i'll do ctrl o and then enter ctrl X and I'll go ahead and repeat the process here and here and we should be good to go for that but the repository will not work without the key so the command for that is this one right here we're going to curl the apt GPG key and we're going to pipe it into sudo apt key ad which is going to add that repository key to our system so enter paste and then enter and we'll do the same thing here as well all right so far so good so now that we have installed that repository we do need to refresh our package index so sudo apt update and I'll do that over here and over here as well now sometimes I do see this error once in a while I am not sure why let's go ahead and give that another shot and it was able to work properly when I tried it again there might be some kind of rate limiting on this repository I'm not exactly sure so if you see an error just give it a moment and then try again as you can see it worked just fine there and it worked just fine on the first one as well okay so now we have the repository the repository is synchronized it's time to install some packages so yet again I'll paste yet another command and using the apt package manager we are installing cube a DM cube control and the cube lip packages so we're installing all three of these in one shot so you basically just press enter enter again to accept the default of yes and we're going to repeat on each node say yes when it asks and basically just wait for it to finish so that one's done that one's done and great we're all set so this command is interesting because the one I'm about to show you should only be run on the master just this one right here we are not going to repeat it on the other nodes only this one and I'm going to go ahead and paste the command and here is that command now to go to into detail about this particular command is beyond the scope of this video but essentially what we're doing is we are setting up the pod network and the service network for our kubernetes cluster and for the domain I just have a sample my domain comm so if you have a company or something like that an actual company domain you could consider putting that in right here and I'm going to go ahead and press Enter and I'll go ahead and let this finish all right so that's all set and that can take a while depending on how fast of an SD card you have and other factors it could take a little while now the most important part of this output is this end part right here this is going to differ from one person to the next so yours will not look exactly like mine but we are going to need this actually we're not going to use it right now what we do want to make a note of this so I'll just copy this text and then I'll just open a text editor window here and I'll make a note of this now you do want to be a little bit protective of this because you don't want this joint command to fall into the wrong hands you especially don't want to show it on a video that thousands of people are going to watch because you don't want any rogue nodes joining your cluster in my case I'm going to delete it anyway so I really don't care and I figured it'd be cool for you to see exactly what that looks like so I'm not going to save this file I'm just going to put it aside for now now also you're going to see some commands that you will need to run like these right here we do need to run those commands actually and those commands we are going to run here on the master so what I'm going to do is copy the first one I'll paste it in enter I'll scroll and get the other commands here so I'll get the second one copy that that one is well press enter and as you can expect we're going to go ahead and get the third one here copy that paste and enter alright so we've run everything there that we need to so I'll clear the screen now what we need to do is install a network driver so I'll paste that command in right here and the first thing you'll notice is that I did not use sudo I don't have sudo in the front of this command that's actually intentional and again all the commands will be in the link in the description below you can pause the video if you would like to and then when you're ready to go ahead and press Enter that should deploy the pod network and you know that was actually pretty quick now we need to make sure that all of the pods that the previous command will create come up properly so I'll paste the next command we're going to use cube control and the more you get into kubernetes the more you'll understand what that means but basically we're going to use this utility we're going to get pods of all namespaces I'll press ENTER and my output is wrapped here but we can see that each of these are running if you have any errors here then you may have done something wrong everything should be running so that means basically that our pod network has been deployed so I'll clear the screen and now the moment of truth I'm going to recall the join command from a previous step I'm going to copy it and we are going to run this on the nodes not the master so I'll go on node number one now to join a node to the cluster I will need to use sudo then I type space and then I'm going to paste the join command there press Enter and now the Burbidge leads me to believe that this was successful so I'll go back here to the master and I'll type cube CTL get nodes and would you look at that we actually have the node right here that we have added to the cluster our first node it's not ready yet but it did actually go ahead and add it so we can just basically run that command again to see if the status changes and we'll do that periodically until it says ready and it does actually already say ready in my case so we do have the master well of course we have the master but we also have our first node added to the cluster so then we can go into the next node you do sudo space and then paste the command back in again and there it is a press enter that's running I'll switch back over to the master and eventually it's going to start showing the other node we only have the first one so far so I'll give it a moment let's try it again and sure enough we have the second node added to the cluster if you have more than two worker nodes then you'll just repeat this same process on each one and then check and make sure that they get a ready status and if it doesn't show ready you basically just wait a few moments and try again and now both of my nodes are ready and have successfully joined my kubernetes cluster well there you go we have successfully created our very own Raspberry Pi based kubernetes cluster how awesome is that now from here you can go ahead and run your containers on this cluster and if this is a topic you guys want to see more content about if I see the interest in the numbers and you guys give this enough likes I am going to consider doing more kubernetes videos for you guys so subscribe to my channel and let me know if this is content that you would like to see more of and regardless I have awesome videos coming guys I can't wait to show you so stay tuned and I'll see you again real soon you
Info
Channel: LearnLinuxTV
Views: 166,970
Rating: undefined out of 5
Keywords: LearnLinux, Linux, Tutorial, Howto, Guide, Distribution, Learn Linux, operating system, os, open-source, open source, gnu/linux, k8s, cluster, docker, container, kubernetes, kubernetes cluster, raspberry pi, pi, raspberry pi 4, raspberry pi 4 projects, raspberry pi projects, docker container, kubernetes tutorial, kubernetes tutorial for beginners, kubernetes architecture, kubernetes cluster raspberry pi, kubernetes cluster raspberry pi 4, kubernetes networking
Id: B2wAJ5FLOYw
Channel Id: undefined
Length: 31min 40sec (1900 seconds)
Published: Wed Feb 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.