LXC | LXD Install | Create & manage Linux LXC Containers | LXDUI Installation | Bridging LXC | LAB

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey folks welcome back to engineer comrades and today we're gonna learn about galaxy and lxd containers we'll see how to create and manage lxc or lxd containers so here is our roadmap first we'll see what is alexey and lxd and how it works after that we'll discuss about some features of lxd and after that we'll start installing lxd then we'll create some containers and we'll see how to manage the containers so by default containers use a netted address so we'll create a bridge interface and then we will map our containers on that bridged interface so that it can directly reached to our physical network card after that we will also see a gui way to manage containers so let's start first what is lxd lxt is an open source container management extension for linux containers actually lxt lxd uses lxc to create containers and it is nothing but a management tool for containers lxd provides new features and functionality like clustering to build and manage linux containers so it has some new features if you compare it with galaxy and what is galaxy lxe is an operating system level virtualization method for running multiple isolated linux systems on a control host using a single linux kernel and now we'll see how actually they use virtualization method so actually linux kernel provides the cz group functionality to lxe that allows prioritization of resources like you can assign a particular set of cpu memory block i o or say network and you can achieve these things without the need for starting any virtual machines so lxc act as a lightweight vms and the namespace functionality provides isolation functionality that allows complete isolation of an application's view of the operating environment including process streams networking user ids and mounted file systems in that way alexey achieves virtualization methods from linux kernel here i have listed some features of lxd first feature is you can use device passthrough capabilities means you can directly assign a hardware to the lxe containers like a network device or a usb device or anything it has also network and storage management capabilities such as storage pooling lxd also supports snapshots of trending containers means if you have a running container you can snapshot that container lxd also support live migration of running containers between hosks lxd can also integrate with cloud platforms such as openstack it has got some improved control over computer resources it also provides clustering so we can make clusters of galaxy containers so now how we gonna proceed with lxd first we will install lxd on our host after that we will initiate lxd actually you have to initiate lxd before creating any containers after that we will create containers and then we'll see how we can place our containers to our physical network device after that we'll also discuss a gui tool which can manage containers in graphical way so in this lab i am going to use ubuntu as my host system you may use any different distro the commands will be much of the same regardless what crystal you are using actually a snapdeal provides us a latest package you may also install lxd using apt-get but uh here i am going to use the snapd first i'm installing a snapd the command is this sudo apt install snapd you may install snapd or you can install lxd using aptcat also after that we will install lxd so command is sudo snap install lxd so as you can see lxd 4.15 has been installed you can also verify if it is installed or not here you can see the electricity group name after that we have to add our username or say user to lxd group so we gonna use sudo user mode hyphen a jncaps lxt and my username so i'm going to use dollar user or you may also type uh username okay so let's type username after adding your user to lxd group actually you have to log in again so you have to log out from your system and then login again so i am going to log out from my system so now i logged back in to my system so now run our first command which is used to check a remote list so command is remote alexi remote list so here is the output of alexa remote list this actually lists list a set of list from that our lxc command will pull the images so first one is from linuxcontainers.org the second one is is local if you have imported any kind of uh image alex image and the third one is ubuntu and the fourth one is ubuntu daily so these are the four remote list you can say or or say a set of urls from from where our galaxy will pull images for our containers these are nothing but the source of images from where you can pull the images so if we want to search image of say ubuntu then we'll type alexey image list and then we'll mark ubuntu this command will give the output of all the available ubuntu containers available from these sources so here you can see we have multiple ubuntu images which alexey fest from the uh remote list you can see here ubuntu 220.04 is listed you have got to point to 18 20 16. so these are the uh list of ubuntu images which alexey actually passed from from the remote list or see the remote urls which i have already showed you earlier so from there actually uh from these four or rather say three uh urls alexey actually fetched these uh lxc images so as i earlier said that before creating any lxc container you have to actually initiate it so first let uh initiate our lxt so command is lxt init so it basically set up a profile uh for our galaxy containers so just execute lxd in it and then it will ask some set of questions so would you like to use electrical string so here i am not going to use clusters so i am going to hit enter and the default is no so it will not create any cluster the next question is do you want to configure a new storage pool yes we do want and for the name i'm going with the default and here the name of the storage backend to use this option is a bit tricky actually uh if you do have a dedicated block of storage say a dedicated hardware hard drive or say any storage device dedicated to containers only then you may use these options also lvmc ph or say uh if you can if you uh can create a different partition then you can also use bt rfs also but we don't have any uh dedicated partition of or say set of uh storage device here so we gonna use dir so it doesn't need any kind of you know the external hard drive or say a separate partition so you have to choose dial here if you don't have any external storage next question is would you like to connect to a mass server so i'm not going to connect to any mass server the default is no hit enter would you like to create a new local network bridge so for right now yes we are going to create a network bridge but you know this network will be will have a different set of ip addresses because this is not a bridged network which is actually bridged to our network interface directly so our containers will run on different ips our different set of ipool so for now we gonna just hit enter and after creating some uh alexi containers will create a bridge to give the same ip address as our host will see that so for now i am just going to hit enter what should the new bridge be called so i am going with default which is lxdbr0 and what ipv4 address should be used i'm going to use default and for this also actually for ipv6 i'm going to use none because in my home infra there is no ipv6 addressing none would you like to expose our lxd servers over the network so if you do need a isolated network alexey containers you can go with defaults or if you want to your alexey containers available over network then you should enter yes so here i am going to choose the option yes because because i don't need any any isolated kind of infra here so for this option i'm going with the default one only and hit enter trust password for new client just hit enter oh sorry trust password for new clients actually you have to enter your password for that i'm going to create a password would you like to steal gasoline is to be updated automatically okay so we are going to use the default option would you like to yaml alexa in it present to be printed okay we are going to use default one only and now our lxd initial configuration has been completed so it is nothing but it created a profile for our galaxy containers having these these all settings so now let's create a container so for creating container we have to type the command galaxy launch and then name of the image so here i am going to use upon to say 18 18.04 and after that you have to name the alexey so here i'm going to name it as ubuntu only so what this command is going to do is it will create a ubuntu named container which will have a image which is ubuntu 18.04 so just hit enter now it's creating our ubuntu container so for the first time it will pull the image from the internet so now our galaxy has been created and is up and running so we can check by uh sorry alexi list comma yeah so here you can see uh ubuntu name container is in running state and this is the ipv4 address the type is container we haven't created any snapshot yet so now let's login to our container so for connecting to container the command is alexey exec and then the instance name here the instance name is ubuntu so we're gonna type ubuntu and then we have to specify what shell we use so here we're gonna use a bash shell to connect to ubuntu and now we are in our container you can verify that this has got the ip 10.226.59.1 so this is our container and you may perform a apt-get update to update all the repository you may also upgrade apt-get upgrade so let's install apache 2 on this alexi container and then we'll expose the port 80 from our host and we'll access the uh port 80 from uh outside of that container so let's do it so just hit get install apache 2 so now as apache 2 has been installed so to expose port 80 to external servers or say from our host if you want to access port 80 of that container we have to execute this command which is nothing but is it is going to add a port which is my port 80 and it will listen on the port 80 and will connect for connect to port 80 only so after uh entering this command it will hit enter and actually i have already uh executed that command so the device already exists so now we are going to check if that apache 2 server which is running an alexi container which is reachable from our host or not so just type 127.0.0.1 colon 80 and now it is the apache to home page so this webpage is actually running in lxc container and we are using or say accessing this webpage from our host machine so in that way we can expose any port of the alexey container to the host so now let's uh let's execute some some commands to manage our galaxy instance so first command is alexey list which i have used earlier so right now we have a single container is running here and the name is ubuntu and that is the ip address if you want to stop this container so simply you can use the command alexey stock and then the name of the instance which is removed in our case so now our ubuntu container will stop so if you list the lxc containers here you can see we do have a container named root google but it is in the stock state so in that way you can stop your container which is alexa stop ubuntu now you can also start your container by using just alexis star to boom so now let's check if the container is started or not so yes the container has been started you can say the state is running you may also delete your container i using this command alexey and then you have to type delete ubuntu or say any instance name or say container name and by entering this command you can delete your container so here i am not going to delete my container actually i have to show you something more on this so let it be running only and uh more command you can use to list your images which you have already installed or say which you have already pulled from the remote servers so you can use lxc image and then list those so we have actually pulled upon to 18.04 lts image from our remote servers and that was 192 megabytes in size you can also transfer files from uh you know from your host to containers or your containers to cost so here i am going to show you a alexey file pull command which will actually uh pull a file from the uh container to the host so first let's create a file in our container so for that we have to login to our containers so the command is alexi exec and then the name of the instance which is upon 2 and the shell which is bash so now we are connected to our container and let's uh create a file so we're gonna use touch and say abc and now we have a file is named as abc and it is placed under root so now log out from our container and we are going to pull that abc file to our host so first yeah so here you can see we don't have any uh file we gonna pull that abc file from from the container so the command is lxc file full and the instance name which is ubuntu in our case and then the path of that file in the container so the path was slash root slash abc and the path of the host which is slash home and slash here so actually we have given a space here which is not required and now file should be copied here so here you can see it has pulled a file from our container to our local host in a similar way you can also pull a folder also so you have to only uh mention hyphen r after pull which is nothing but a recursive command which gonna pull the whole folder from that so that's it so now we'll move on to our next top pack which is uh so as you can see our alexey container is running but it is running on you know a different uh ip from our host so if you will check the host address so host is running on 192.168.43.56 the host ip addresses whereas the uh container id is 10.226.59.194 so actually it has created a bridge which is by default uh given this ip and if you want to bridge the container to our physical interface or say on that pool you have to create a new bridge and you have to assign that bridge to this container so we will also do that so for creating a bridge you may have or you can have multiple ways to set up a bridge connection i will show you how to create a bridge using anom connection editor you may use an mcli or say net plan but here i am going to use a num connection editor tool so just use this command and i'm connection editor and i'm iphone connection and editor so this is the easiest way of creating a bridge and uh it's it's kind of a hybrid way i'll say because you have you can use a gui tool and to create a bridge you have to click on this plus sign and now we have to create a bridge so you have to select bridge from the virtual section so just create a bridge and we are going to create a bridge name bridge 0 and you have to also sign that on which port this bridge is going to be created so here i am going to select ethernet and then i am going to select my device so my host is having a ethernet cable connection so i am going to use ens33 which is nothing but my lan port so just select it and then click on save hit save and now you can see you do have a new connection name bridge connection one so let's try to up that new created port so i'm going to use the command sudo and mcli and the connection up which watch bridge connection one okay so let's see what we have created it was raised connection one okay so b is in caps that actually we are entering wrong here so just put b is in caps so as you can see we have successfully activated our bridge connection so after that actually we have to only restart our system now you can see the ens 33 which was earlier our primary interface and it is up but that interface has not assigned has been not assigned any ip address and we do have the ip address on our bridge 0 which we have created earlier so now we have created our bridge 0 so now assign this bridge 0 to our linux containers so that our container can be on the same network address pool so first of all we'll check if any container is running or not yes ubuntu is running so first i'm going to stop that so let's see stop ubuntu and after that we are going to add this h0 to our based network so just hit enter after that and now you can say device 80 has been added to ubuntu container so now let's start our ubuntu container so let's see start ubuntu and now list the containers once again and you can see the container is running but we haven't got any ip address yet so actually we have to wait for that it has been bridged to our bridge zero interface and should get the ip of of the of our local network only yeah so as you can see we have got an ip address of 192 192.168.43.57 which is our local network so in this way you can also bridge your containers to your physical network or say your local network so now your host machine and your containers container is on the same network so that's it for the lxc containers and now we are going to discuss about uh lxd gui which is lx dui so we are going to install the lxd ui and uh then we gonna explore some uh settings which actually we can alter by using a gui interface so first we have to clone the lxd ui from github so lx the ui github yeah so here it is from this way you can use a gui interface to interact with your containers yeah so these are the commands i will put all the commands and all the links and the description box only so you can check it out from there so first we have to clone this yeah so it is not installed actually so we are going to install it first yeah so now jit has been installed so we're gonna execute our cloning command so we're gonna load the lxd ui from github so has been cloned and now we are going to install a lxd ui so first enter in the directory and after that we're gonna install by using pip3 install user command just paste that one python three pip is not installed so we have to install that one also so so let's install it so now pip3 has been installed so now we'll start our installation process of lxd ui so here you can see we have got some warnings but there is no error so we are fine and now we are going to start our lxd ui by executing this command python3 run dot py and then start as you can see the lxd ui has been started on this port 1515 one so let's visit that website yeah so we have successfully connected to the web interface of the lxd ui now the default username password is admin and admin so username is admin and the password is also admin so now hit login i'm gonna save it and yes now you have a running graphical container management system which is alex t ui and you can see you have one instance of ubuntu which is running here and it has got an ip address of 43.57 you can clone the container from here you can move that or you can directly go to terminal of that of that you know container so you can check this yeah so it's 43.57 so you can connect the console from the web ui only you can clone the containers from here you can jump it in the terminal of that container you can snapshot the container and also after selecting that check box you may stop the container so now you can say this container has been stopped you can also start it by just clicking on the check box and then hit start so there are various options of you know the start stop restart delete freeze and unplease which you can execute against any containers which are listed here you can also create new instances like uh you can select the image from here also yes we do have only one image right now so i don't think that it provides all the images from the remote list one second let's check in the images section if we can pull the images from here also let's verify that one so i think yeah yeah so locally we do have one image which have already pulled upon to 18.04 and we do have these you know these container images from our remote list so actually you can create from uh from this list also so so let's create one so let's create one so let's create something which i'm gonna use somewhere so if if you can find a search option yeah so we have a search option here so yeah so i'm going to create a container of send os 8 and let's select the proper image for that and i think this one it's amd 64. yeah and this one is good for me i think so i'm going with this one yeah so here now you can see we are downloading that centos 8 image from the remote server it will take some time to you know to extract the 123 mps so let's wait to finish that yeah so we have successfully downloaded the image so just close it now you can see in our local repository we have two images one we have used earlier ubuntu and now we have sent os eight also in our repository so so check this one and you can launch the container from here only so just click on launch container and now you can name it so i am gonna name it send os date and the quantity is one actually it is the number of containers you want to create so for me i am going to create only one container for now and i am just unchecking this box autostart means whenever your host will be restarted the container will start automatically i am gonna uncheck this one cpu allocation in percentage so i'm going with default for now and now i'm going to create that one so now you you can see our sent os eight has created and which is currently stopped so now start and let's see if the container is running or not yeah so container center essay it has been successfully started so jump into the terminal of that yes our centos 81 actually centos 81 is up and running and you can check the ip address yeah so by default it is using the uh netted ip which is 10.226.59.154 you have to again you know bridge to bridge zero interface and you can have this container also on your local network so for today i think uh we have created container using cli method also we have seen lxd ui from where you can manage your containers in a graphical way so that's it for today and if you liked our video or say our content so please consider subscribing my channel and also hit the like button so we'll meet the next time with some interesting video so for now thanks for watching and bye
Info
Channel: Engineer Comrades
Views: 1,226
Rating: undefined out of 5
Keywords:
Id: jIDwxE3TN_w
Channel Id: undefined
Length: 41min 24sec (2484 seconds)
Published: Sun Jun 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.