Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
Formatting and order rewrite
  • Loading branch information
cfoos authored Sep 25, 2024
1 parent a87cef5 commit 902aff2
Showing 1 changed file with 96 additions and 56 deletions.
152 changes: 96 additions & 56 deletions tools/k3s/readme.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,57 @@
These are the config files I used to get this running on k3s. I'm using rook-ceph for storage and metallb to expose the dashboard on an ip. Any pvc will need to be updated to the storage of the cluster this is deployed on, and the grafana service will need to be updated to what is being used to expose services on that cluster as well.
# Powerwall Dashboard on Kubernetes

You will need to manually import the influxdb.sql
These config files can be used to get Power-Wall Dashboard runningo n k3s. These files assume you are using metallb for ingress and rook-ceph for storage. You will need to update grafanaservice.yaml if you are using something other than metallb, and the pvc configs if you are using storage other than rook-ceph. Local storage pvc configs are provided for testing but should not be used in deployment.

example:
kubectl get pods -n powerwall|grep influx
influxdb-5db4797475-b5z44 1/1 Running 0 3h35m

kubectl cp influxdb.sql -n powerwall influxdb-5db4797475-b5z44:/influxdb.sql
kubectl exec --stdin --tty -n powerwall influxdb-5db4797475-b5z44 -- /bin/bash
root@influxdb-5db4797475-b5z44:/# influx -import -path=influxdb.sql
## Configuration
Update the values in the following files




To test this you can use a Raspberry pi 4 4G with a thumb drive. Install Ubuntu server 24.04 onto the thumb drive using the rpi imager and ssh to it.

sudo su - into root and run:
configmap.yaml update the following section with your powerwall details
```bash
sed -i '$ s/$/ cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory/' /boot/firmware/cmdline.txt
```
and this but remove the wifi part if you are using wifi as this turns it off
```bash
echo -e "dtoverlay=disable-wifi\ndtoverlay=disable-bt\ngpu_mem=16" >> /boot/firmware/config.txt
email: "user@domain.tld"
password: "supersecurepass"
host: "xx.xx.xx.xx"
pwtz: "America/Chicago"
timezone: "America/Chicago"
```
Then you will want to set your pi to have a static ip either in the config or on your dhcp server and update /etc/hosts to use that ip for the pi's hostname. You will also need to setup the ip routing for accessing the powerwall, I just set this on my router so I do not have to mess with individual machines.

Then you will need to run
```bash
apt install libraspberrypi-bin net-tools ntp snapd lvm2 build-essential golang git kubetail -y
```
followed by an upgrade and reboot
grafanadatasources.yaml update these with your lat/lon
```bash
apt update
apt upgrade -y
reboot
"latitude": "xx.xxxx",
"longitude":"xx.xxxx"
```

Once the pi is back online you can install k3s, I sudo into root to do this.
weather411config.yaml add your api key, update lat/lon and set the units to your desired format
```bash
curl -sfL http://get.k3s.io | sh -s - server --disable servicelb,traefik --cluster-init
APIKEY = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
LAT = xxx.xxxx
LON = yyy.yyyy
UNITS = metric
```
and verify it is online by running
kubectl get nodes

Now for metallb so we can give grafana an ip run:
```bash
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.5/config/manifests/metallb-native.yaml
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
```
Then edit metallb-config.yml to set an ip range metallb can assign out and apply it and metalLbL2Advertise.yaml
grafanaservice.yaml set the ip address you want grafana to have
```bash
kubectl apply -f metallb-config.yml
kubectl apply -f metalLbL2Advertise.yaml
loadBalancerIP: xx.xx.xx.xx
```

Make sure all your pods are running with
```bash
kubectl get pods --all-namespaces
```

Now we can start with the powerwall stuff. First make the namespace
## Deployment
You will first need to setup the namespace
```bash
kubectl apply -f namespace.yaml
```
Then edit configmap.yaml to add your powerwall login and ip, grafanadatasources with your lat/lon for sun and moon plugin, grafanaservice.yaml with the ip you want grafana to have, and weather411config.yaml with your api and lat/lon.

Once that is done you can apply the configs and pvcs.
Next is the configs and pvc's
```bash
kubectl apply -f configmap.yaml -f grafanadatasources.yaml -f grafanapvc-local.yaml -f influxdbpvc-local.yaml -f pypowerwallpvc-local.yaml -f telegrafconfig.yaml -f weather411config.yaml
kubectl apply -f configmap.yaml -f grafanadatasources.yaml -f grafanapvc.yaml -f influxdbpvc.yaml -f pypowerwallpvc.yaml -f telegrafconfig.yaml -f weather411config.yaml
```

Then we can apply the deployments and services.
Finally we can set up the deployments and the services so we can access them
```bash
kubectl apply -f grafanadeployment.yaml -f g
rafanaservice.yaml -f influxdbdeployment.yaml -f influxdbservice.yaml -f pypowerwalldeployment.yaml -f pypowerwallservice.yaml -f telegrafdeployment.yaml -f weather411deployment.yaml -f weather411service.yaml
```

Check the pods to see when they are all running
Check the pods to see when they are all running, garafana can take a few minutes but everything should be up in under 5 minutes in most cases
```bash
kubectl get pods -n powerwall
```
Expand All @@ -86,7 +61,11 @@ Once all the pods are in a running state you can check the grafana service to ve
root@k3stest:~/Powerwall-Dashboard/k3s# kubectl get services -n powerwall|grep grafana
grafana LoadBalancer 10.43.179.85 192.168.2.125 3000:30466/TCP 28m
```
get your influxdb pod name

The second ip is the metallb load balancer ip and the first port is the exposed one so at this point assuming the grafana pod started without issues this install would be accessable at:
http://192.168.2.125:3000

Before we can do anything in grafana you need to get your influxdb pod name
```bash
kubectl get pods -n powerwall|grep influx
influxdb-5db4797475-b548p 1/1 Running 1 (6m50s ago) 31m
Expand All @@ -103,9 +82,70 @@ kubectl exec --stdin --tty -n powerwall influxdb-5db4797475-b548p -- /bin/bash
root@influxdb-5db4797475-b548p:/# influx -import -path=influxdb.sql
```


log in and add the influxdb data source with url of
Now you can log into grafana and add the influxdb data source
http://influxdb.powerwall:8086

then add the dashboard k3sdashboard.json
the dashboard still needs some work and the solar flow plugin is not very useful intill the latest version gets on grafanas site from github.
1. From `Configuration\Data Sources` add `InfluxDB` database with:
- Name: `InfluxDB`
- URL: `http://influxdb.powerwall:8086`
- Database: `powerwall`
- Min time interval: `5s`
- Click "Save & test" button

Once that is done you can add the dashboard
k3sdashboard.json



## Test Environment

To test this you can use a Raspberry pi 4 4G with a thumb drive. Install Ubuntu server 24.04 onto the thumb drive using the rpi imager and ssh to it.

sudo su - into root and run:
```bash
sed -i '$ s/$/ cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory/' /boot/firmware/cmdline.txt
```

and this but remove the wifi part if you are using wifi as this turns it off
```bash
echo -e "dtoverlay=disable-wifi\ndtoverlay=disable-bt\ngpu_mem=16" >> /boot/firmware/config.txt
```

Then you will want to set your pi to have a static ip either in the config or on your dhcp server and update /etc/hosts to use that ip for the pi's hostname. You will also need to setup the ip routing for accessing the powerwall, I just set this on my router so I do not have to mess with individual machines.

Then you will need to run
```bash
apt install libraspberrypi-bin net-tools ntp snapd lvm2 build-essential golang git kubetail -y
```

followed by an upgrade and reboot
```bash
apt update
apt upgrade -y
reboot
```

Once the pi is back online you can install k3s, I sudo into root to do this.
```bash
curl -sfL http://get.k3s.io | sh -s - server --disable servicelb,traefik --cluster-init
```
and verify it is online by running
kubectl get nodes

Now for metallb so we can give grafana an ip run:
```bash
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.5/config/manifests/metallb-native.yaml
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
```
Then edit metallb-config.yml to set an ip range metallb can assign out and apply it and metalLbL2Advertise.yaml
```bash
kubectl apply -f metallb-config.yml
kubectl apply -f metalLbL2Advertise.yaml
```

Make sure all your pods are running with
```bash
kubectl get pods --all-namespaces
```

From this point you can do the same install as above, but use the -local version of the pvc files.

0 comments on commit 902aff2

Please sign in to comment.