We’ve been talking to people about how to wire up K8s clusters, so they can use Fly to front-end their applications by just hosting haproxy on us and bouncing requests to their own network.
There’s a bunch of different ways to do that, and we’re exploring all of them. But one simple approach you can take is to simply have every one of your K8s nodes bring up an independent connection to Fly, for instance via a DaemonSet.
So we’ve tried to make that easy to do with a new API for building WireGuard connections.
The thing we think you don’t want to do is to load a full-fledged Fly access token into every one of your nodes (ick!). So we’ve created a limited-purpose WireGuard token that can only be used to add new WireGuard connections to an organization (or to rekey them). You mint a token (or several, however you want to carve it up; when you delete a token, you delete every associated WireGuard connection), and hand it out to your Pod or whatever. The token case be used — via a REST interface you can drive from curl — to create or update a named WireGuard connection.
It looks like this:
curl -v
-H "Authorization: Bearer ${FLY_WIREGUARD_TOKEN}"
-H "Content-Type: application/json"
--request POST
--data '{"name": "node-1", "group": "k8s", "pubkey": "<c25519>", "region": "dev"}' https://fly.io/api/v3/wire_guard_peers
The PUT to v3/wire_guard_peers/:name
will accept “pubkey” to re-key a connection (in other words: if you’re replacing a Pod or a container under the same name, your new instance can reclaim the connection.)
You may have noticed the group
in the JSON: it can be whatever, and we’ll populate <groupname>._g.internal
with the peers under it in our DNS.
<c25519>
needs to be a valid Curve25519 public key, a WireGuard key. You can generate them with wg
's tooling, or with flyctl
.
flyctl
can drive this API, with flyctl token create
, and then flyctl token start
to create a new connection and flyctl token update
to rekey. start
and update
expect the token in the env var FLY_WIREGUARD_TOKEN
.
This is a super specific and corner-casey thing that might not be relevant for most of you, but it might make some system design tasks simpler for some of you. Thoughts welcome!