I Installed Kubernetes On My Old PC – Here’s How I Did It

Containers are extremely useful in scenarios where you want to run a specific application or software without the extra resource overhead of a virtual machine. Kubernetes serves as a great … Read more

Taylor Bell

Taylor Bell

Published on Jul 21, 2024

I Installed Kubernetes On My Old PC – Here’s How I Did It

Containers are extremely useful in scenarios where you want to run a specific application or software without the extra resource overhead of a virtual machine. Kubernetes serves as a great platform to deploy and manage all your containers, and it’s worth learning for anyone who’s into DevOps.

Fortunately, you don’t need to set up complex operating systems or gather a bunch of nodes. If you have a spare PC lying around, you can turn it into a Kubernetes server with the help of MicroK8s.

What you’ll need

The mainboard of the Lenovo ThinkServer SR250 V2

Unless you plan to deploy hundreds of containers, you should be fine with any PC from the last decade, assuming it can run Linux, of course. Speaking of, you’ll require an operating system pre-installed before proceeding to the rest of the article.

Ideally, you should go with Talos Linux if you’re planning to venture deep into the Kubernetes ecosystem. But since this guide is geared towards the average user who just wants to run K8s on their outdated system, we’ll go with Ubuntu. I’ll admit, it’s quite inefficient to run Kubernetes on everybody’s favorite golden boy of the Linux world, but its ease of access, combined with SSH support, make the process far easier for beginners.

For those worried about the lower performance of Ubuntu’s GUI, you can replicate the entire project on Ubuntu Server, since the entire procedure will feature terminal commands. Finally, we’ll go with the MicroK8s package to further reduce the complexity of the project.

A screenshot of the initial Ubuntu setup with the Location option highlighted

Related

How to install Ubuntu

Want to install Ubuntu in place of Windows or another operating system? We run you through the entire process

Installing MicroK8s

Once you have Ubuntu installed, it’s time to get started with the installation procedure.

  1. Launch the terminal app by pressing Ctrl+Alt+T.
  2. Install the snapd package by executing the following command: sudo apt install snapd -y
    Installing the Snapd package in the Ubuntu terminal

  3. Run this command in the terminal to install the MicroK8s package.
    sudo snap install microk8s --classic
    Installing the MicroK8s package in the Ubuntu terminal

  4. With the help of the usermod command, grant admin access to the current user.
    sudo usermod -a -G microk8s $USER
    Using the usermod command in the Ubuntu terminal

  5. Create a new directory called be and use chmod to grant full access to the user.
    mkdir -p ~/.kubechmod 0700 ~/.kube
    The commands to create the kube directory and modify its access permissions in the Ubuntu terminal

  6. Refresh the session with the updated privileges using the are command.
    su - $USER
    Th su command in the Ubuntu terminal

    Be sure to enter the root password when prompted by the terminal.

  7. Finally, initialize the MicroK8s service.
    microk8s start
    Starting the MicroK8s service in the Ubuntu terminal

Accessing the web dashboard for MicroK8s

MicroK8s has a robust online interface that makes it easy to manage your containers. But you’ll need to enable it in the terminal.

  1. Launch an instance of the MicroK8s Dashboard by running this command:
    microk8s enable dashboard
    Enabling the MicroK8s Dashboard in the Ubuntu terminal

  2. Use the proxy argument to make the Dashboard accessible from a web browser.
    microk8s dashboard-proxy
    Starting the MicroK8s Dashboard proxy service in the Ubuntu terminal

  3. Click on the 127.0.0.1:10443 URL and choose to Agree and accept the risks under the Advanced tab when your browser cautions you against opening the Dashboard.
    Opening the MicroK8s Dashboard in Ubuntu

  4. Use the token generated inside the terminal to log into the Dashboard.
    Logging into the MicroK8s Dashboard on Ubuntu

Once inside the dashboard, you keep track of all your pods, their resource consumption, and other details. If you’re not willing to dabble in terminal commands yet, the Dashboard is a great means to familiarize yourself with Kubernetes’ working.

Creating a container in MicroK8s

Using the Web Dashboard

Of course, this tutorial would be incomplete if we didn’t deploy a container. There are several methods you can use to accomplish this, but I’ll highlight two of my preferred ways, with the first one involving the Dashboard we accessed earlier.

  1. On Dashboard home page, click on the + icon.
    The Plus icon in the MicroK8s Dashboard

  2. Hit Upload after entering the code for the YAML configuration file containing the details about the image, template, metadataand other parameters under the Create from input tab to initialize your first container.
    Enter the YAML file code to create a container using the MicroK8s Dashboard

  3. Alternatively, you can switch to the Create from file tab and pick the YAML/JSON file stored on your system.
    Picking the YAML file to create a container using the MicroK8s Dashboard

    Be sure to hit the Upload button afterward.

  4. For an even simpler option, you can navigate to Create from form tab and Deploy the container after specifying its details.
    Deploying a container using the MicroK8s Dashboard

Using Docker images

Since Docker provides easy access to a host of useful container images, I recommend giving it a shot if you want pre-created images.

  1. Install the Docker package by running the following command.
    sudo apt-get install docker.io -y
    The terminal command to install the Docker package in Ubuntu

  2. Just like before, run usermod to provide administrator privileges to the main user before restarting the session with the help of the are command.
    sudo usermod -aG docker ${USER}su - ${USER}
    The terminal command to modify the privileges to the Docker group in Ubuntu

  3. Use the docker pull command to grab your favorite image.
    docker pull image_name
    The terminal command to pull a Docker image in Ubuntu

    I’ve used httpd from Apache for this tutorial, but you can also use other lightweight web server images.

  4. Enable the MicroK8s registry and allocate sufficient storage to it using the size argument:
    microk8s enable registry:size=100Gi
    The terminal command to enable the MicroK8s registry in Ubuntu

  5. Next, tag the docker image you’d like to use for a MicroK8s container before pushing it to the MicroK8s registry operating on the localhost with the post number 32000.
    docker tag image_name localhost:32000/image_namedocker push localhost:32000/image_name
    The terminal command to add a docker image to the MicroK8s registry in Ubuntu

  6. (Optional) If Docker displays errors when adding the image to the MicroK8s registry, you’ll need to modify the daemon.json file. First, open it using the nano editor.
    sudo nano /etc/docker/daemon.json
    The terminal command to access the daemon.json file in Ubuntu

    Then, enter the following arguments before pressing Ctrl+X and tapping Y to save and exit the file.

    {"insecure-registries" : ["localhost:32000"]}
    The new arguments for the daemon.json file in Ubuntu

    Be sure to restart the Docker to apply the changes using the systemctl command:

    sudo systemctl restart docker
  7. Deploy the MicroK8s container by running the following command:
    microk8s kubectl create deployment container_name --image=image_name
    The terminal command to deploy a MicroK8s container using a Docker image in Ubuntu

  8. You can use the get pods command to verify whether the container was created successfully.
    microk8s kubectl get pods
    The terminal command to check the MicroK8s pods in Ubuntu

Assuming you’ve already set up the Dashboard earlier, the container will appear on the web UI alongside its pod(s) and replica(s).

Using a spare PC to gain informative hands-on experience with Kubernetes

The MicroK8s Dashboard running on Ubuntu

With that, you should know everything to dip your toes into the wonderful (and complicated) world of Kubernetes. Once you’ve gained a strong grasp of MicroK8s, you can install Talos Linux and set up multiple nodes for a full-fledged installation of Kubernetes.

In case you want a simple means to create containers and virtual machines without dabbling in the witchcraft of K8s, I recommend giving Proxmox a shot. It’s an excellent platform that combines an easy-to-use UI with robust features, and is worth checking out even if you’re completely new to the field of virtualization.

macOS Sonoma running on a Proxmox virtual machine

Related

I tried running macOS on Proxmox — here’s how it went

Thanks to Proxmox, you can convert any old PC into a Hackintosh

Partager cet article

Inscrivez-vous à notre newsletter