This repository provides a Vagrantfile to spin up a single Ubuntu 24.04 VM, provision a user with SSH key authentication, and guide you through installing a k3s cluster with monitoring via kube-prometheus-stack (Prometheus + Grafana + Alertmanager).
- Vagrant
- KVM/Libvirt
- SSH public key to inject into the VM
Open up the Vagrantfile in your favorite editor and replace any of these values if needed.
!! Be sure that the Public Key path points to a valid path !!
USERNAME = "kube"
PUBLIC_KEY_PATH = File.expand_path("~/.ssh/id_ed25519.pub")
HOSTNAME = "k3s-single"
IPADDR = "192.168.122.42"Clone this repository and run:
vagrant upThis will:
- Launch an Ubuntu 24.04 VM
- Create a user (kube)
- Add your SSH key
- Grant password-less sudo access
To SSH into the VM:
ssh -l kube 192.168.122.42On the VM, install k3s (single-node):
curl -sfL https://get.k3s.io | sh -
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown kube: ~/.kube/config
export KUBECONFIG=~/.kube/configVerify that the node is up
kubectl get nodesIt should give an output similar to this
kube@k3s-single:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3s-single Ready control-plane,master 35s v1.33.4+k3s1
kube@k3s-single:~$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm versionIt should give an output similar to this
kube@k3s-single:~$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11913 100 11913 0 0 76590 0 --:--:-- --:--:-- --:--:-- 76858
Downloading https://get.helm.sh/helm-v3.18.6-linux-amd64.tar.gz
Verifying checksum... Done.
Preparing to install helm into /usr/local/bin
helm installed into /usr/local/bin/helm
kube@k3s-single:~$ helm version
version.BuildInfo{Version:"v3.18.6", GitCommit:"b76a950f6835474e0906b96c9ec68a2eff3a6430", GitTreeState:"clean", GoVersion:"go1.24.6"}
kube@k3s-single:~$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo updatekubectl create namespace monitoringhelm install kps prometheus-community/kube-prometheus-stack -n monitoringkubectl get pods -n monitoringIt should give an output similar to this
kube@k3s-single:~$ kubectl get pods -n monitoring
NAME READY STATUS RESTARTS AGE
alertmanager-kps-kube-prometheus-stack-alertmanager-0 2/2 Running 0 92s
kps-grafana-b456ddcf7-2nx8g 3/3 Running 0 98s
kps-kube-prometheus-stack-operator-56d87dbbdf-s2q7c 1/1 Running 0 98s
kps-kube-state-metrics-6ff8469dcf-t5qq6 1/1 Running 0 98s
kps-prometheus-node-exporter-chszk 1/1 Running 0 98s
prometheus-kps-kube-prometheus-stack-prometheus-0 2/2 Running 0 92s
kube@k3s-single:~$ Get the Grafana Admin password Hint: It's most probably "prom-operator"
kubectl get secret --namespace monitoring kps-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echoPort-forward the Grafana service
kubectl port-forward --address 0.0.0.0 -n monitoring svc/kps-grafana 3000:80Then open http://192.168.122.42:3000
- Username: admin
- Password: From the secret above ("prom-operator")
You can just run vagrant destroy -f outside the virtual machine to destroy the entire virtual machine and k3s setup, but if you want to only remove kube-prometheus-stack you can use the following commands.
helm uninstall kps -n monitoring
kubectl delete namespace monitoring
kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
kubectl delete crd alertmanagers.monitoring.coreos.com
kubectl delete crd podmonitors.monitoring.coreos.com
kubectl delete crd probes.monitoring.coreos.com
kubectl delete crd prometheusagents.monitoring.coreos.com
kubectl delete crd prometheuses.monitoring.coreos.com
kubectl delete crd prometheusrules.monitoring.coreos.com
kubectl delete crd scrapeconfigs.monitoring.coreos.com
kubectl delete crd servicemonitors.monitoring.coreos.com
kubectl delete crd thanosrulers.monitoring.coreos.comNow we are back to the state we were in before we installed the kube-prometheus-stack
kube@k3s-single:~$ kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k3s-single Ready control-plane,master 12m v1.33.4+k3s1 192.168.121.23 <none> Ubuntu 24.04.3 LTS 6.8.0-71-generic containerd://2.0.5-k3s2
kube@k3s-single:~$
kube@k3s-single:~$ kubectl get pods -owide --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system coredns-64fd4b4794-wv9hd 1/1 Running 0 13m 10.42.0.5 k3s-single <none> <none>
kube-system helm-install-traefik-crd-2lvfc 0/1 Completed 0 13m 10.42.0.2 k3s-single <none> <none>
kube-system helm-install-traefik-kvhjj 0/1 Completed 2 13m 10.42.0.3 k3s-single <none> <none>
kube-system local-path-provisioner-774c6665dc-cvgsr 1/1 Running 0 13m 10.42.0.4 k3s-single <none> <none>
kube-system metrics-server-7bfffcd44-6zzp7 1/1 Running 0 13m 10.42.0.6 k3s-single <none> <none>
kube-system svclb-traefik-2b77385f-mxtsx 2/2 Running 0 12m 10.42.0.7 k3s-single <none> <none>
kube-system traefik-c98fdf6fb-fgphp 1/1 Running 0 12m 10.42.0.8 k3s-single <none> <none>
kube@k3s-single:~$ If you want to uninstall k3s, run the following command
sudo /usr/local/bin/k3s-uninstall.shAnd to get rid of the entire virtual machine, log out of the ssh-session and run vagrant destroy -f
$ vagrant destroy -f
[fog][WARNING] Unrecognized arguments: libvirt_ip_command
==> k3s-single: Removing domain...
==> k3s-single: Deleting the machine folder
$