Pengen Ngulik Infra? Setup KVM di WSL2 aja! Modal Laptop Biasa Cukup
Kubernetes Lab on KVM WSL Journey
Part 1 of 5
Tutorial lengkap bikin homelab KVM di laptop biasa pakai WSL2. Gak perlu sewa cloud mahal-mahal, cukup modal laptop kentang!
TL;DR: Pengen belajar infrastruktur tapi budget pas-pasan? Tenang, kita bakal transform laptop biasa jadi homelab KVM yang powerful pakai WSL2. Siap-siap jadi infrastructure engineer tanpa keluar duit banyak! π
Kenapa Harus Repot-repot? π€
Sebelum kita dive in, mungkin ada yang bertanya: βNgapain sih ribet-ribet setup KVM di laptop kalau bisa sewa VPS?β
Simple answer: Skills > Money πͺ
- VPS costs money yang mungkin belum ada sebagai fresh graduate
- Learning by doing jauh lebih powerful daripada cuma baca-baca teori
- Portfolio builder - recruiter bakal impressed sama yang punya pengalaman hands-on
- Flexibility - bisa eksperimen sebanyak yang diinginkan tanpa takut tagihan membengkak
π§ Pre-requisites: Yang Dibutuhin
Before we start, pastikan sudah punya:
β
Windows 10/11 dengan WSL2 enabled
β
Minimal 8GB RAM (16GB recommended kalau mau nyaman)
β
CPU yang support virtualization (Intel VT-x atau AMD-V)
β
Space kosong minimal 50GB buat VM-VM nanti
β
Mental yang kuat buat debugging (this is important! π
)
π Step 1: Setup Foundation - Enable Nested Virtualization
First things first, kita perlu mastiin nested virtualization aktif. Ini basically virtualization di dalam virtualization - mind blown right? π€―
Cek Status Current
cat /sys/module/kvm_intel/parameters/nestedExpected output: Y (kalau Intel) atau cek /sys/module/kvm_amd/parameters/nested kalau AMD.
Kalau Belum Aktifβ¦
Buka PowerShell as Administrator di Windows, terus jalanin:
# Cek nama WSL distro
wsl --list --verbose
# Replace 'Ubuntu' dengan nama distro
wsl --shutdown Ubuntu
Get-VMProcessor -VMName "Ubuntu" | Set-VMProcessor -ExposeVirtualizationExtensions $true
wsl -d UbuntuPro tip: Kalau command di atas error, coba restart Windows dulu. Sometimes Windows just needs a good olβ reboot π
π οΈ Step 2: Install KVM Stack - The Real Deal
Sekarang saatnya install semua tools yang dibutuhin. Copy-paste is your friend here:
# Update system dulu biar gak ada drama
sudo apt update && sudo apt upgrade -y
# Install KVM dan kawan-kawannya
sudo apt install -y \
qemu-system \
qemu-utils \
libvirt-clients \
libvirt-daemon-system \
bridge-utils \
virt-manager \
cpu-checker \
libguestfs-tools \
libosinfo-bin
# Bonus tools yang bakal berguna nanti
sudo apt install -y \
python3 \
python3-pip \
genisoimage \
wget \
curl \
unzipAdd User ke Libvirt Group
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
# Logout terus login lagi biar changes take effect
exit
# Buka WSL lagiβ‘ Step 3: Fire Up the Services
# Enable dan start libvirt services
sudo systemctl enable --now libvirtd
sudo systemctl enable --now virtlogd
# Cek status - harus running semua
sudo systemctl status libvirtd
sudo systemctl status virtlogdValidation Time! π―
# Command ini bakal ngecek semua requirements
sudo virt-host-validate
# Kalau ada yang FAIL, jangan panik dulu
# Beberapa warnings itu normal di environment WSL2What to expect: Beberapa checks mungkin WARN atau FAIL, especially yang berkaitan dengan hardware security. Thatβs totally fine untuk learning environment!
ποΈ Step 4: Setup Terraform + Libvirt Provider
Sekarang kita bakal install Terraform buat Infrastructure as Code experience yang lebih pro:
Install Terraform
# Add HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | \
sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
# Add repository
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
# Install Terraform
sudo apt update && sudo apt install terraform -y
# Verify installation
terraform --versionSetup Libvirt Provider
# Create directory structure
mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.7.1/linux_amd64
# Download libvirt provider (adjust version as needed)
cd /tmp
wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.8.3/terraform-provider-libvirt_0.8.3_linux_amd64.zip
# Extract dan install
unzip
mv terraform-provider-libvirt_v0.8.3 ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.8.3/linux_amd64/terraform-provider-libvirt
chmod +x ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.8.3/linux_amd64/terraform-provider-libvirtπΎ Step 5: Storage Management yang Rapi
Kita perlu setup storage pools buat organize ISO files dan VM disks. Think of it as creating folders, but fancier:
# Create directories
sudo mkdir -p /data/isos
sudo mkdir -p /data/vms
sudo chown -R $USER:$USER /data/
# Define storage pools
virsh pool-define-as vms dir - - - - "/mnt/d/kvm/vms" # Adjust path as needed
virsh pool-define-as isos dir - - - - "/mnt/d/kvm/isos" # Adjust path as needed
# Set autostart (biar otomatis start pas boot)
virsh pool-autostart vms
virsh pool-autostart isos
# Start the pools
virsh pool-start vms
virsh pool-start isos
# Verify
virsh pool-list --allExpected output: Both pools should show as active dan autostart yes.
π Step 6: Virtual Networking Setup
Time to create isolated networks buat VM-VM. Ini penting banget buat simulate real-world scenarios:
Create Network Definition
# Create network config file
cat > /tmp/net-lab.xml << 'EOF'
<network>
<name>net-lab</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr-lab' stp='on' delay='0'/>
<domain name='lab.local'/>
<ip address='192.168.100.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.100.10' end='192.168.100.100'/>
</dhcp>
</ip>
</network>
EOF
# Define and start the network
virsh net-define /tmp/net-lab.xml
virsh net-autostart net-lab
virsh net-start net-lab
# Verify
virsh net-list --allπ― Step 7: Quick Test - Download dan Test ISO
Mari kita test setup dengan download ISO dan create VM pertama:
# Download Ubuntu Server ISO (lightweight option)
cd /mnt/d/kvm/isos
wget https://releases.ubuntu.com/noble/ubuntu-24.04.2-live-server-amd64.iso
# Create your first VM via command line
virt-install \
--name test-vm \
--ram 1024 \
--vcpus 1 \
--disk path=/mnt/d/kvm/vms/test-vm.qcow2,size=10 \
--os-variant ubuntu24.04 \
--network network=net-lab \
--graphics none \
--console pty,target_type=serial \
--location /mnt/d/kvm/isos/ubuntu-24.04.2-live-server-amd64.iso,\
initrd=casper/initrd,\
kernel=casper/vmlinuz \
--extra-args 'console=ttyS0,115200n8 serial --- quiet'π¨ Common Issues & Troubleshooting
βPermission deniedβ errors
# Fix libvirt permissions
sudo chmod 666 /var/run/libvirt/libvirt-sock
# Or add to group (better solution)
sudo usermod -aG libvirt $USERβNested virtualization not supportedβ
- Restart Windows completely
- Check BIOS settings - enable Intel VT-x atau AMD-V
- Verify WSL2 VM settings dalam Hyper-V
VMs super slow
- Allocate more RAM ke WSL2 di
.wslconfig - Enable CPU extensions di VM creation
π Whatβs Next? Level Up Your Game!
Congrats! Sekarang sudah punya homelab KVM yang functional. Selanjutnya bisa:
π₯ Create multi-VM clusters buat simulate production environments
π₯ Experiment dengan Kubernetes tanpa takut break production
π₯ Practice Infrastructure as Code dengan Terraform
π₯ Build CI/CD pipelines yang deploy ke VM clusters
π₯ Learn container orchestration dengan setup sendiri
Pro Tips buat Next Steps:
- Automate everything - Write Terraform configs buat VM provisioning
- Monitor your lab - Install Prometheus + Grafana
- Practice disaster recovery - Backup dan restore VMs
- Document everything - Future self will thank present self
π Closing Thoughts
Setup KVM di WSL2 might seem overwhelming di awal, tapi trust me - ini investment terbaik yang bisa dilakukan buat career development. Dengan homelab sendiri, bisa:
- Experiment freely tanpa takut biaya cloud
- Build real-world experience yang recruiters appreciate
- Stay updated dengan latest infrastructure trends
- Debug skills yang invaluable di production environments
Remember: Every senior engineer started somewhere. Yang penting mulai, learn from mistakes, dan keep iterating. Good luck, dan happy learning! π
Punya pertanyaan atau stuck di salah satu step? Bisa reach out di email phamminhphueur@gmail.com! Letβs build this infrastructure community together πͺ
Next post: βBikin Kubernetes Cluster di KVM - From Zero to Heroβ - Stay tuned! π