This guide sets up a lightweight Kubernetes cluster using K3s on a virtual machine, deploys a Prometheus monitoring stack via Helm, and exposes both Grafana and Prometheus dashboards using NodePort.

# Create environment script
cat <<EOF > k3s-env.sh
#!/bin/bash
export INSTALL_K3S_CHANNEL=stable
export INSTALL_K3S_EXEC="--disable=traefik --disable=servicelb --disable=metrics-server"
export K3S_KUBECONFIG_MODE="644"
export INSTALL_K3S_NAME="k3s"
EOFchmod +x k3s-env.sh
source ./k3s-env.shcurl -sfL https://get.k3s.io | sh -
kubectl get nodesmkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $USER:$USER ~/.kube/configcurl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm versionhelm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo updatehelm install prometheus prometheus-community/kube-prometheus-stack \
--set grafana.persistence.enabled=true \
--set grafana.persistence.size=2Gi \
--set grafana.adminUser="admin" \
--set grafana.adminPassword="prom_operator" \
--set grafana.grafana.ini.database.wal=true#Alternatively you can put all the dependables into a yaml file and apply during the install
kubectl patch svc prometheus-grafana -p '{"spec": {"type": "NodePort"}}'
kubectl get svc prometheus-grafana
# Note the NodePort (e.g. 32185)# URL format: http://<VM_IP>:<NodePort>
# Example: http://100.91.78.70:32185- Username: admin
- Password: prom_operator
kubectl patch svc prometheus-kube-prometheus-prometheus -p '{"spec": {"type": "NodePort"}}'
kubectl get svc prometheus-kube-prometheus-prometheus
# Note the NodePort (e.g. 32290)URL format: http://<VM_IP>:
Example: http://100.91.78.70:32290

