Windows Subsystem for Linux setup WSL2 Systemd, Ansible, and Kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
windows subsystem for Linux is a fantastic tool that if you're not using it already you need to be it is a great way to easily get your hands on a Linux distribution to play around with in your home lab environment if you're delving into devops if you're trying to learn new Linux skills if you just need a bash shell a true bash shell to interact with various systems and use native Linux tools Windows subsystem for Linux allows you to do that without the need to spin up a full virtual machine using something like virtualbox or VMware Workstation in today's video I'm going to step you guys through tweaks and tips for setting up your windows subsystem for Linux WSL environment in a way that allows you to carry out devops processes interact with various systems run ansible code play around with kubernetes and the list goes on and on so let's dive into my list of ultimate WSL tweaks and tips that you need to know the first thing that we want to consider is actually getting WSL windows subsystem for Linux install on your Windows host if you have installed WSL in the past you know that from experience this has been a piecemeal of commands of packages that you have to download and have to install such as the kernel update for Linux that you need to install on your Windows system once you actually have WSL installed however if you've not heard of this recently Microsoft has made WSL available as a native Microsoft Store app what that means is you no longer have to concern yourself with all these little steps and all of the additional packages that you need to install and wonder if you have the latest version now that Microsoft has made this natively available on the Mac Microsoft Store it simplified this process greatly let's take a look at what that looks like from the Microsoft store if you launch the Microsoft store on your Windows 10 or Windows 11 workstation and you search for WSL you're going to find the available windows subsystem for Linux that is natively found on the Microsoft store it means that you can install Windows subsystem for Linux as you would any other Microsoft app from the Microsoft store so it's really awesome so very cool all we have to do is simply install this app now you may be wondering how do you know if you have installed this from the Microsoft store actually fairly easy to tell if you're running the Microsoft store version of WSL in fact if you issue the WSL dash dash version it will show you all the versions for WSL the WSL version the kernel version and so on and so forth if you are running the operating system integrated version of WSL in other words the version that you have downloaded from a Microsoft download site issuing the command WSL dash dash version will not return in fact it'll error out saying that it doesn't know what that parameter is now it's an easy process to override the current version of WSL that you have running as well as you simply go out and install this from the Microsoft store it will overwrite the WSL version that you had that was integrated or that you had downloaded from the Microsoft download site so it's they've made it fairly easy there's not a lot of steps that you have to go through to purge your system of the old version of WSL so you can install the Microsoft store app in fact it just simply overrides what you have now that we have Windows subsystem for Linux installed from the Microsoft store which is the latest version we can get into some of these awesome tweaks that I want to share with you guys one of the first tweaks is how to suppress the sudo password prompt for your sudo user as this can get cumbersome if you're performing lots of operations requiring sudo privileges so let's see how this is done as you can see I have finished initializing a brand new Ubuntu WSL environment and I have created the user Linux admin to avoid the process of having to enter the sudo password each time we need to perform a sudo operation we can modify the vi pseudo file to actually allow this user and designate this user to bypass the sudo password prompt to do that we're just going to issue the command student advice suit and we're going to scroll to the bottom and we're simply going to paste in a command designating the user which is Linux admin and all equals all no password colon all and with that configuration we're simply going to just save out and save our changes with that configuration now we will not be prompted for a sudo password when we need to perform CB operations now with the permissions out of the way we can get to the fun stuff we can actually install utilities and other tweaks that are awesome and I use these daily in my WSL configuration the next weekend configuration that I want to show you guys is how to enable WSL with systemd functionality up until just recently installing system D in a WSL environment was fairly complicated requiring lots of config changes lots of hacks and installation of various packages just to get systemd working however this is Now natively supported many packages require systemd like micro Cades if you want to play around with that package as well as many others you need systemd so let's see how this is easily enabled we simply need to edit the Etsy wsl.config file by default there is nothing in the file however we want to place some config in the WSL file and that config is the boot stanza and we're going to put the configuration systemd equals true and that's it we just simply exit out of the file saving our changes now what we need to do is is we need to shut down WSL and we're going to shut down our WSL incense that simple we have now shut down the WSL instance I'm going to close that Tab and we're going to go back into our wso instance to verify that systemd is indeed installed we can issue the command system CTL list unit files dash dash type equals service and there we have it we've got systemd installed and up and running as we can see the status of our services using the system CTL command the first tool that I install in my WSL environment is ansible ansible is a fantastic Automation and configuration management tool and platform that allows you to automate literally everything from network devices to servers to virtualization environments Windows Linux the list goes on and on it's a great way to automate things in the home lab and in production environments installing ansible in WSL is very simple we simply need to chain a few commands together to install all of the prerequisites as well well as the ansible package itself so I'm going to paste those commands into the command window first line we are installing some prerequisites as well as the krb-5-dev package which is one of the prerequisites for working with Kerberos as you can see later in the command stanza we've got the APT install krb5-user and this package allows us to use ansible to not only work with Linux environments but we can also work with Windows environments that are domain joints and we can use Kerberos authentication to authenticate with ansible to those windows targets so let's kick off these commands and we will install ansible now we are asked the default Kerberos version 5 realm I'm going to enter that now now our ansible Command set has completed successfully so we should be able to enter the ansible dash dash version command and see that ansible is installed which it is now that we've installed ansible I want to show you guys another cool tweak that I do with my WSL environment and that is adding persistent aliases persistent aliases allow us to create short commands that may refer to much longer commands and one of the really cool and easy use cases that I have for installing persistent aliases is referencing directories such as for my ansible configuration to create a persistent Alias we need to create a special file that's located in the home directory that is called The Bash aliases file to create that file I'm just simply issuing a touch command and we're going to create the file and now we're going to edit the file now that we have the file in place let's see how we can actually create an alias so I'm going to paste in a command that I typically use especially with my ansible configuration and when you guys see the directory structure you will understand why I want to create an alias for this my ansible code is found in a OneDrive folder that is mounted via the path that you see here so I always create an alias ansible dur or ansible directory Alias that allows me to easily get to that ansible location as you can see here it's under the C drive but the path is extremely long let's see how this works so now I need to exit out and save our changes to this bash underscore aliases file we need to close out of the command console window as these do not become active until we re-initialize our wso Command configuration can simply issue the command ansible dur and it should change us directly into the long directory path that we have as part of the Alias awesome so now we can just issue the command ansible dur and it automatically shifts me into the directory that I want to be able to get to to see all of my ansible configuration Powershell is arguably one of the coolest and most handy utilities that you can install in any environment including WSL and it's easy to install and it's a tweak and install of a Configuration utility that I always do with my WSL environments how can we easily install the Powershell core cross-platform installation in WSL the commands needed to install Powershell in our WSL environment are actually not that many it's fairly straightforward and the process is not difficult at all so what I want to do is just simply paste in the commands required to install Powershell in our WSL and environment while it looks fairly busy what we've got going on it's actually fairly straightforward first we are simply installing the prerequisites needed for Powershell next we are downloading the gpg key the official key for installing the Powershell repository from which we will install Powershell next we are installing the repository next we are simply updating our catalog of applications now we are adding the universe repository and finally we are actually installing Powershell core in our Ubuntu WSL environment so let's execute this command and we will have Powershell installed in our WSL environment the list of commands have completed successfully so now let's see if we actually have Powershell installed and for Powershell core that command is pwsh and as we can see we have successfully installed Powershell 7.3.1 which is the latest version of Powershell as of the making of this video now that we have Powershell installed let's actually add a very useful module if you are working with VMware vsphere and that is the install module VMware our CLI the VMware power CLI module for Powershell is the official module that allows us to interact with the VMware vsphere API carrying out automated tasks and commands and processes in our VMware vsphere environment this is extremely helpful for automation for reporting purposes for troubleshooting for quick tasks that you need to carry out in bulk and I use this daily with my VMware vsphere environment now that the VMware power CLI module is installed we can issue the command connect VI server and this is the official commandlet that allows us to verify that we are indeed invoking the VMware power CLI module for Powershell and we are we can see that it's prompting us for our vcenter server I've already shown you guys how we can create an alias who reference a locally mounted directory I want to show you guys with WSL how you can easily find and navigate local Windows directories and reference files that are located there one of the really cool things that we can now do with the current version of WSL that was more challenging in previous versions was actually copy files into our WSL installation and copy files back and forth between WSL and our host machine I want to show you guys how you can quickly do this from the command line nwsl and bring up an Explorer window that you can use to copy files or even edit files back and forth forth from your Windows host workstation and your WSL environment so let's take a look at this back and forth file navigation both from a WSL perspective as well as from our Windows host how we can look at files and edit files from both perspectives first we've already looked at this just a bit with creating the file Alias but local machine files on your Windows host are presented to WSL at a mount point I can literally change directory to mount C and we just simply follow the user path here as we would in Windows and with just that simple change directory as you can see I am now navigating the host WSL directory structure of my Windows host now one other really cool thing that I want to show you guys that was extremely difficult or cumbersome in previous versions of WSL and that was actually editing files in the WSL environment from your Windows host I want to show you guys how much easier this is with modern versions of WSL in case you have not seen this so to literally open a location in your WSL environment you simply navigate to the point you want to open so I'm in my home directory and I just simply issued the explorer.exe command with a period in other words telling explore.exe I want to expose or present this particular location of my WSL environment to my Windows host so let's see what happens so now I am dragging over the Explorer window that just opened in my windows post and here we see the home directory of my Linux admin account mounted for me in my Windows host so I can literally edit files if I want I can copy files back and forth I can create files all of this from my Windows host workstation which is awesome what about installing kubernetes inside WSL with the functionality now added with systemd we can now install micro case which is a tiny kubernetes distribution from canonical that allows you to quickly and easily spin up kubernetes clusters let's see how we can install micro case inside our WSL environment and start easily working with kubernetes clusters now I'm going to show you guys just how easy it is to get up and running with micro Kates in a WSL environment as you saw just a few steps ago we were able to enable system D that is actually required for microcates now let's look at installation of microcates that command is sudo snap install micro case classic once we issue the command the micro Cates insulation begins and just a few moments later we have a successful installation of micro Cades so we can issue commands such as sudo micro case status as we can see micro Cates is running and as expected it's not running in high availability mode we can now issue commands such as sudo micro case food CTL get nodes and there we go we see we've got our single node microcates installation up and running we can do Dash o y to get even further information so this is an excellent way to experiment with kubernetes without having to spin up virtual machines or other infrastructure just to get your hands on the technology minicube is another popular solution for playing around with kubernetes can we install this in wsl2 well let's take a look first we need to install a few prerequisites and I'm just going to paste these in we're performing a sudo apt-get update apt-get install see certificates curl GN UPG and LSB release next we're going to install the official Docker gpg key now we set up the Repository we perform an apt-get update now we can actually install docker next we're going to add our current user into our Docker group to interact with Docker next we're going to install contract foreign steps completed we can actually begin the installation of minicube itself so let's step through those commands now we're going to pull down the mini Cube release next we're going to make that release executable now we're going to move the mini Cube executable into our user local bin directory we're going to set the configuration to use our Docker driver now that we have mini cube in place we're going to install Kube CTL and set the context to minicube now we can actually start the minicube cluster excellent now the installation of minicube is complete in WSL using the installation of systemd as well as the prerequisites that we have just ran through now let's use Coupe CTL and actually look at our clustered awesome there we see our mini Cube cluster ready with the control plane sitting at version 1.25.3 what do you guys think about these WSL tweaks that allow you to get up and running with the latest functionality that windows subsystem for Linux offers I think it's a great utility and I use it especially on my windows workstation when I need access quick and easy to a Linux environment or a native Linux bash shell how are you using Linux in your environment are you using WSL let me know in the comments well I'm Brandon Lee please do like the video subscribe to the channel I hope you guys are staying safe out there and please do check back often as I have more great content coming your way take care guys I will see you guys soon thank you
Info
Channel: VirtualizationHowto
Views: 37,987
Rating: undefined out of 5
Keywords:
Id: CouuH3W6ZtA
Channel Id: undefined
Length: 20min 50sec (1250 seconds)
Published: Tue Dec 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.