Kubernetes manifests for a public node, and --announce

k8s/base (kustomize): StatefulSet with a volume, p2p LoadBalancer for 4001
TCP+UDP, ClusterIP for the UI, optional ingress; k8s/overlays/nodeport for
clusters without a load balancer. The pod waits for 'allmende init' so the
recovery phrase never goes to a log.

--announce makes a node that sits behind a router or in a container announce
the address others can dial (e.g. /dns4/name/tcp/4001), so a bootstrap node
behind a port forward works, and the DNS records it prints name the host.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 11:40:25 +01:00
co-authored by Claude Sonnet 5.5
parent dd229895f4
commit 819df6d512
15 changed files with 431 additions and 1 deletions
+17
View File
@@ -31,6 +31,7 @@ import (
"github.com/libp2p/go-libp2p/p2p/discovery/mdns"
drouting "github.com/libp2p/go-libp2p/p2p/discovery/routing"
"github.com/libp2p/go-libp2p/p2p/host/autorelay"
ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
"git.stinnesbeck.com/nils/allmende/internal/identity"
@@ -69,6 +70,11 @@ type Config struct {
// address or a forwarded port). It then serves the DHT and acts as a relay
// for nodes behind a NAT, which is what a bootstrap node does.
Public bool
// Announce lists the addresses other nodes should dial, without /p2p/<id>,
// e.g. /dns4/node.example.org/tcp/4001. A node behind a router or in a
// container does not know its public address; when this is set, only these
// addresses are announced.
Announce []string
// PeerCache is a file in which the node remembers its peers between runs;
// empty turns that off.
PeerCache string
@@ -167,6 +173,17 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
autorelay.WithMinCandidates(1),
autorelay.WithNumRelays(2)),
}
if len(cfg.Announce) > 0 {
announce := make([]ma.Multiaddr, 0, len(cfg.Announce))
for _, a := range cfg.Announce {
m, err := ma.NewMultiaddr(a)
if err != nil {
return nil, fmt.Errorf("announce address %q: %w", a, err)
}
announce = append(announce, m)
}
opts = append(opts, libp2p.AddrsFactory(func([]ma.Multiaddr) []ma.Multiaddr { return announce }))
}
if cfg.Public {
opts = append(opts, libp2p.ForceReachabilityPublic(), libp2p.EnableRelayService(), libp2p.EnableNATService())
}