DEV Community

Cover image for Making a local MicroK8s environment available externally (Part 1 - Building a Linux VM)
Peter Davis
Peter Davis

Posted on

Making a local MicroK8s environment available externally (Part 1 - Building a Linux VM)

I'm currently building an Open Source LegalTech platform called Panache Legal which is built using .NET and consists of a number of microservices which are all designed to run in Docker containers. This all works great locally, but one issue is how to host a version externally that can be used by colleagues for testing and demos.

Of course that's easy right, I've got docker images uploaded to docker hub, so just spin those up as web apps in Azure (or your cloud provider of choice) and it's problem solved.

But where is the fun in that. I don't really want to pay for too many hosted services, but most importantly, I want to learn more about Kubernetes and the whole DevOps pipeline. In short, I'd like to do it myself.

So here's what we're going to do instead.

  • Create a Linux VM locally in Hyper-V
  • Install MicroK8s and MySQL (including phpMyAdmin)
  • Get Panache Legal (or your docker images of choice) up and running on that VM

The above gives us a local Kubernetes environment using MicroK8s, but because we want that accessible externally, and because I don't have a static IP from my ISP, we'll have to jump through some additional hoops to expose this to the outside world. So we'll follow this up and...

  • Create a Linux VM in Azure
  • Setup SSH port forwarding to send traffic to and from that Azure VM to my local VMs

Now, there are many different ways we could have done this, like using WSL, using a local linux workstation, running it all in a VM in Azure, running MicroK8s on Windows. Plus there are security considerations around opening a route to our local network....but we've got to start somewhere, so lets go with the route outlined above and just get going, and hopefully, even if the whole setup isn't valid for you, parts of it might be.

Creating our Hyper-V Linux VMs

Before we start, go ahead and download a copy of the Ubuntu installation ISO from Ubuntu desktop. Other flavours of Linux are available if you prefer.

I'm creating this environment in Windows 11 and you'll need the Pro or Enterprise version to use Hyper-V. If you're looking for a free alternative you could likely use VirtualBox to achieve the same result.

Hyper-V won't be enabled by default so you'll need to open Control Panel > Programs and Features > Turn Windows features on or off and make sure Hyper-V is enabled.

Windows features Hyper-V

Open up Hyper-V Manager and the first thing we'll do is use the Virtual Switch Manager... action to create an External Switch to allow our VM to see the outside world.

External switch setup

Once that's done use the New > Virtual Machine... action to create our VM. Give your VM a name and then you can choose either Generation 1 or Generation 2. Assign as much memory as you want and then make sure you choose your newly created External Switch for the networking.

When you get to Installation Options choose Install an operating system from a bootable image file and select the Ubuntu ISO you downloaded earlier and then finish.

I'm aware we could have used the Hyper-V Quick Create... option, but again, I like to do all of this myself so I'm familiar with the setup.

Before we go any further make sure you open the Settings... of your new VM. If you choose to use Generation 2 untick Enable Secure Boot so we don't get any issues with the Ubuntu installation. Also check on the Memory and Processor settings, you may want to adjust what's assigned here based on the spec of your machine.

Now simply use the Connect... option and start up your VM. You should boot into the install screen

Ubuntu Install

Choose the Install Ubuntu option and then from their go with the defaults or options appropriate for you. When it comes to the Updates and other software screen I choose a minimal installation as I'm not going to be using the VMs for anything other than running MicroK8s and MySQL.

After the install has finished you'll boot into the desktop.

Ubuntu Desktop

It's likely the auto software updater will run, so let it do its thing and once that's done we're almost ready to install MicroK8s and MySQL, there are just a couple of extra steps that might make our life easier.

SSH Setup

I generally use Windows Terminal (which you can download from the Microsoft Store) to interact with my Linux VMs but that needs us to have SSH running on our VMs, and Ubuntu does not come with that pre-installed, so let's get that up and running.

Open a new terminal window with Ctrl+Alt+T and use the following commands to install openssh-server.

sudo apt update
Enter fullscreen mode Exit fullscreen mode
sudo apt install openssh-server
Enter fullscreen mode Exit fullscreen mode

That should be all that's needed and we can confirm that we can login by opening windows terminal on our host and using

ssh {username}@{VM name}
Enter fullscreen mode Exit fullscreen mode

Windows Terminal SSH

Desktop Resolution

It's likely we'll do everything via windows terminal from this point onwards, but if you want to use the Linux desktop for anything you'll find that by default you can't change the resolution to anything better than the fairly disappointing 1024x768.

To fix this we need to make a couple of tweaks. Open a terminal with Ctrl+Alt+T and then use the nano editor (or vim if you prefer) to edit the grub file.

sudo nano /etc/default/grub
Enter fullscreen mode Exit fullscreen mode

Find the line that begins with GRUB_CMDLINE_LINUX_DEFAULT and add video=hyperv_fb:1920x1080 to the end. You can use whatever resolution is suitable for your monitor.

In addition to this you also want to edit the line that begins with GRUB_CMDLINE_LINUX and make sure that is the same.

Things should look a little like this.

Edit Grub file

Save and exit the editor, Ctrl+x then Y then Enter in nano.

and then run the following command.

sudo update-grub
Enter fullscreen mode Exit fullscreen mode

Reboot your VM and you should find it starts back up with your new resolution set.

Next steps

At this point we should our Linux VM up and running.

Lets head over to part two of this guide where we'll go through the installation of MicroK8s and MySQL.


Buy Me A Coffee

Top comments (0)