- Published on
Setup a KVM Host for Virtualization on OneProvider
- Authors
- Name
- Ruan Bekker
- @ruanbekker
I've been on the hunt for a hobby dedicated server for a terraform project, where I'm intending to use the libvirt provider and found one awesome provider that offers amazingly great prices.
At oneprovider.com, they offer dedicated servers for great prices and they offer a huge number of locations. So I decided to give them a go and ordered a dedicated server in Amsterdam, Netherlands:
I went for a 4GB DDR3 RAM, Atom C2350 2 Cores CPU with 128GB SSD and 1Gbps unmetered bandwidth for $7.30 a month, which is super cheap and more than enough for a hobby project:
I've been using them for the last week and super impressed.
What are we doing
As part of my Terraform project, I would like to experiment with the libvirt provisioner to provision KVM instances, I need a dedicated server with KVM installed, and in this guide we will install KVM and create a dedicated user that we will use with Terraform.
Install KVM
Once your server is provisioned, SSH to your dedicated server and install cpu-checker
to ensure that we are able to install KVM:
$ apt update && apt upgrade -y
$ apt install cpu-checker -y
Test using kvm-ok
:
$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
On a client pc, generate the SSH key that we will use to authenticate with on our KVM host:
$ ssh-keygen -t rsa -C deploys -f ~/.ssh/deploys.pem
Back on the server, create the user and prepare the ssh directory:
$ useradd -m -s /bin/bash deploys
$ mkdir /home/deploys/.ssh
$ touch /home/deploys/.ssh/authorized_keys
On the client PC where you generated your SSH key, copy the public key:
$ cat ~/.ssh/deploys.pem.pub| pbcopy
Paste your public key to the servers authorized_keys file:
$ vim /home/deploys/.ssh/authorized_keys
# paste the public key contents and save
Update the content below with the correct permissions:
$ chown -R deploys:deploys /home/deploys
$ chmod 755 /home/deploys/.ssh
$ chmod 644 /home/deploys/.ssh/authorized_keys
Install KVM on the host:
$ apt install bridge-utils qemu-kvm libvirt-bin virtinst -y
Add our dedicated user to the libvirt group:
$ usermod -G libvirt deploys
Create the directory where we will store our vm's disks:
$ mkdir -p /opt/kvm
And apply ownership permissions for our user and group:
$ chown -R deploys:libvirt /opt/kvm
I ran into a permission denied issue using terraform and the dedicated user, and to resolve I had to ensure that the security_driver
is set to none
in /etc/libvirt/qemu.conf
:
$ vim /etc/libvirt/qemu.conf
and update the following:
security_driver = "none"
Then restart libvirtd:
$ sudo systemctl restart libvirtd
Test KVM
Switch to the deploys
user:
$ sudo su - deploys
And list domains using virsh
:
$ virsh list
Id Name State
----------------------------------------------------
Thank You
Thanks for reading, feel free to check out my website, and subscribe to my newsletter or follow me at @ruanbekker on Twitter.
- Linktree: https://go.ruan.dev/links
- Patreon: https://go.ruan.dev/patreon