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
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.
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.
- Launch the terminal app by pressing Ctrl+Alt+T.
- Install the snapd package by executing the following command: sudo apt install snapd -y
- Run this command in the terminal to install the MicroK8s package.
sudo snap install microk8s --classic
- With the help of the usermod command, grant admin access to the current user.
sudo usermod -a -G microk8s $USER
- Create a new directory called be and use chmod to grant full access to the user.
mkdir -p ~/.kubechmod 0700 ~/.kube
- Refresh the session with the updated privileges using the are command.
su - $USER
Be sure to enter the root password when prompted by the terminal.
- Finally, initialize the MicroK8s service.
microk8s start
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.
- Launch an instance of the MicroK8s Dashboard by running this command:
microk8s enable dashboard
- Use the proxy argument to make the Dashboard accessible from a web browser.
microk8s dashboard-proxy
- 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.
- Use the token generated inside the terminal to log into the Dashboard.
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.
- On Dashboard home page, click on the + icon.
- 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.
- Alternatively, you can switch to the Create from file tab and pick the YAML/JSON file stored on your system.
Be sure to hit the Upload button afterward.
- For an even simpler option, you can navigate to Create from form tab and Deploy the container after specifying its details.
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.
- Install the Docker package by running the following command.
sudo apt-get install docker.io -y
- 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}
- Use the docker pull command to grab your favorite image.
docker pull image_name
I’ve used httpd from Apache for this tutorial, but you can also use other lightweight web server images.
- Enable the MicroK8s registry and allocate sufficient storage to it using the size argument:
microk8s enable registry:size=100Gi
- 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
- (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
Then, enter the following arguments before pressing Ctrl+X and tapping Y to save and exit the file.
{"insecure-registries" : ["localhost:32000"]}
Be sure to restart the Docker to apply the changes using the systemctl command:
sudo systemctl restart docker
- Deploy the MicroK8s container by running the following command:
microk8s kubectl create deployment container_name --image=image_name
- You can use the get pods command to verify whether the container was created successfully.
microk8s kubectl get pods
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
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.
Related
I tried running macOS on Proxmox — here’s how it went
Thanks to Proxmox, you can convert any old PC into a Hackintosh