Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
119 lines
6.9 KiB
Markdown
119 lines
6.9 KiB
Markdown
# Running a public node on Kubernetes
|
|
|
|
This runs one Allmende node as a **bootstrap node**: the address new nodes
|
|
use to find the network (`_dnsaddr.allmende.stinnesbeck.com`). It serves the
|
|
DHT and relays for nodes behind a NAT. It also works behind your home router.
|
|
|
|
```
|
|
k8s/base/ namespace, StatefulSet (+1 Gi volume), Services, config
|
|
k8s/base/ingressroute.yaml the web UI on a public name, a Traefik IngressRoute
|
|
k8s/overlays/nodeport/ variant for a cluster without a load balancer
|
|
```
|
|
|
|
## Does it work behind a router?
|
|
|
|
Yes, with a port forward. A bootstrap node must be dialable from the internet,
|
|
so:
|
|
|
|
1. **Forward port 4001, TCP and UDP**, on the router to the cluster (the
|
|
LoadBalancer address, or with the `nodeport` overlay a node's address on
|
|
port 30401). UDP matters: it carries QUIC, which most nodes prefer.
|
|
2. **Give the router's public IP a DNS name** (an A record, or dynamic DNS if
|
|
your IP changes) and put it in `base/config.env` as `PUBLIC_HOST`.
|
|
A node in a pod or behind a router cannot know its own public address, so
|
|
it announces that name (`--announce`) instead. Because the name, not an IP,
|
|
goes into the DNS records below, a changing IP only needs the A record
|
|
updated, not the `_dnsaddr` records.
|
|
3. If your provider puts you behind carrier-grade NAT (no real public IPv4),
|
|
forwarding cannot work. Use a small VPS instead, or IPv6 if your network
|
|
gives you a routable address.
|
|
|
|
## Setup
|
|
|
|
1. **Image.** Build it from the `Dockerfile` in the repository root, push it
|
|
to a registry the cluster can pull from, and set `images:` in
|
|
`base/kustomization.yaml`.
|
|
```
|
|
docker build -t git.stinnesbeck.com/nils/allmende:<tag> . && docker push git.stinnesbeck.com/nils/allmende:<tag>
|
|
```
|
|
2. **Name.** Edit `base/config.env` (`PUBLIC_HOST`, and `PUBLIC_PORT` if the
|
|
router cannot forward 4001 to 4001; `REGION` if the node should keep
|
|
listings for a region). `DIFFICULTY` (24) is the network's proof-of-work and
|
|
must match every other node: at another value this node refuses their
|
|
listings and they refuse its. Moving from the old 16 needs the new image too.
|
|
3. **Apply.**
|
|
```
|
|
kubectl apply -k k8s/base # with a LoadBalancer (MetalLB, kube-vip, ...)
|
|
kubectl apply -k k8s/overlays/nodeport # or: NodePort 30401, no load balancer
|
|
```
|
|
On its first start the pod creates its identity by itself
|
|
(`allmende init --no-phrase`): no recovery phrase is made or logged. The keys
|
|
and the database live on the volume (`data-allmende-0`). **Keep that volume**
|
|
(and back it up if you can): the peer ID in your DNS records is stored there.
|
|
4. **Publish the DNS records.** The node prints them at start:
|
|
```
|
|
kubectl -n allmende logs allmende-0 | grep dnsaddr=
|
|
```
|
|
Add each line as a TXT record at `_dnsaddr.allmende.stinnesbeck.com` (the
|
|
value is the whole `dnsaddr=...` text). Check:
|
|
```
|
|
dig +short TXT _dnsaddr.allmende.stinnesbeck.com
|
|
```
|
|
5. **Try it from outside your network** (a phone on mobile data, or a VPS):
|
|
```
|
|
allmende init && allmende run # no --bootstrap needed
|
|
```
|
|
Within a minute its status (`/api/v1/status`) should show a peer.
|
|
|
|
## Good to know
|
|
|
|
- **The identity lasts a year, and cannot be renewed.** A certificate is valid
|
|
for at most 366 days, and without a recovery phrase nothing can sign a new
|
|
one. The node warns in its log 30 days before and refuses to start after.
|
|
Then: delete the volume (or its contents), let the pod start again (a new
|
|
identity, so a new peer ID), and replace the `dnsaddr=` records with the new
|
|
ones from the log. Do it a few days early and keep the old records until the
|
|
new node is up. If you would rather have a renewable identity, create it once
|
|
by hand with a phrase (`allmende init`, without `--no-phrase`) on the volume
|
|
before the first start.
|
|
- **Metrics.** The node serves Prometheus metrics on container port 9090
|
|
(`--metrics`): peers (and peers per region), listings held, gossip dropped or
|
|
rejected, peers banned, sync and connections refused, and Go memory. They show
|
|
whether the node is being attacked or running short of memory. The port has no
|
|
login and no Service or IngressRoute points to it, so only things inside the
|
|
cluster can reach it; keep it that way. Scrape it with a PodMonitor
|
|
(`port: metrics`) or `kubectl -n allmende port-forward allmende-0 9090:9090`
|
|
and `curl localhost:9090/metrics`. Counters start at zero on every restart.
|
|
- **One replica only.** A second pod would be a second node with its own
|
|
identity, not a copy.
|
|
- **No sign-in link in the log.** `allmende run` normally prints the owner
|
|
sign-in link (it holds the admin token) to the terminal, which in Kubernetes
|
|
is the pod log. The manifest passes `--no-login-link`, so it is left out.
|
|
When you do want to sign in, read the token yourself and open
|
|
`http://localhost:8080/#/login/<token>` through the port-forward below:
|
|
`kubectl -n allmende exec allmende-0 -- cat /data/admin.token`
|
|
- **The web UI** is published through Traefik by `ingressroute.yaml` (host in
|
|
that file). The same port serves the owner API, which the admin token
|
|
protects. To keep it private, comment the file out in `base/kustomization.yaml`
|
|
and use `kubectl -n allmende port-forward svc/allmende-http 8080:8080`.
|
|
- **Regions.** A bootstrap node follows none by default. To make it also keep
|
|
listings, either set `REGION` in `base/config.env` (a place name or a
|
|
3-character geohash, several separated by commas: `REGION=mechernich`) and
|
|
apply again, or open the UI through the port-forward, sign in and choose
|
|
regions there. A choice made in the browser is kept on the volume and wins
|
|
over `REGION` from then on; delete `/data/regions.json` to use `REGION`
|
|
again. Do not edit the `args` script in `statefulset.yaml` for this: a missing
|
|
trailing `\` there silently drops `--announce` (see below).
|
|
- **"--public, but this node has no public address" in the log** means the node
|
|
runs without `--announce`, so it only knows the pod's private address and
|
|
advertises that. Check that the live StatefulSet's `args` still contain both
|
|
`--announce` lines and that every line of the `set --` command but the last
|
|
ends in `\` (`kubectl -n allmende get statefulset allmende -o yaml`). The
|
|
warning says which case it is: no `--announce` at all, or one that is not
|
|
publicly reachable. An empty `PUBLIC_HOST` stops the pod with an error instead.
|
|
- **More than one bootstrap node** on different networks makes the network
|
|
independent of any single one. Run this on a second cluster or a VPS and add
|
|
its records next to the first.
|
|
- **Upgrades.** `make image` builds and pushes the image tagged with the commit (clean tree only); put that tag in `newTag` and the image digest next to it (how: see the comment in `base/kustomization.yaml`), apply again. The cluster pulls by digest. `allmende version` and the "node running" log line show which commit runs.
|
|
The pod restarts; peers reconnect on their own.
|