Labels and selectors
Every server and proxy in a Minekube network is an instance with labels: stage=lobby, game=arena, mode=solo. Where code needs a server, it names a selector instead of an address, the way Kubernetes picks pods. A server can restart under a new key, move to another host or sit behind NAT, and the selector still finds it.
Instances and labels
Section titled “Instances and labels”An instance is a running server or proxy with the Minekube plugin and its connector. Its identity is its key, kept in instance.key in the plugin folder and made on first start. Its labels say what it is.
| What | Set by | Example |
|---|---|---|
| Your labels | You, in the instance’s connector.json |
stage=lobby, game=arena, mode=solo |
System labels, under minekube.com/ |
The registry | minekube.com/, minekube.com/, minekube.com/region=… |
| Entry label | You, on the instances players join first | minekube.com/entry=true |
- The registry sets the system labels: the platform (
paper,velocity), its version, and the region of the instance’s home relay when it is known. Your own labels underminekube.com/are dropped, exceptminekube.com/entry. minekube.com/entry=truemarks where players land when they join the network’s address: the proxy, or a server that runs without one.- Labels give no rights. Only an instance whose key belongs to the network is part of it.
- The instance’s status (online, players, free slots) is not a label. Selectors pick by labels, and the status decides among the matches.
Selectors
Section titled “Selectors”A selector is a Kubernetes LabelSelector: matchLabels and matchExpressions with the operators In, NotIn, Exists and DoesNotExist. The same selector has a text form, as in kubectl -l:
| Text | Means | Becomes |
|---|---|---|
stage=lobby (or ==) |
The label equals the value | matchLabels |
tier!=cache |
The label differs, or is missing | NotIn |
mode in (solo,duo) |
The label is one of the values | In |
mode notin (solo,duo) |
The label is none of the values, or is missing | NotIn |
draining |
The label exists | Exists |
!beta |
The label does not exist | DoesNotExist |
Separate requirements with commas: game=bedwars,mode in (solo,duo),!beta. Every requirement must hold, and an empty selector matches every instance.
A key is a name of up to 63 characters, letters and digits at both ends and -, _ or . between, optionally after a DNS prefix and a slash, as in minekube.com/entry. A value is empty or such a name.
Selectors in code
Section titled “Selectors in code”@minekube/ is the implementation the registry and the CLI use: the Schema, the text form and matching.
import * as LabelSelector from "@minekube/network/LabelSelector";import { Effect } from "effect";
const lobbies = Effect.gen(function* () { // { matchLabels: { game: "bedwars" }, matchExpressions: [{ key: "mode", operator: "In", values: ["solo", "duo"] }, { key: "beta", operator: "DoesNotExist" }] } const selector = yield* LabelSelector.parse("game=bedwars,mode in (solo,duo),!beta"); const matches = LabelSelector.matches(selector); return [matches({ game: "bedwars", mode: "solo" }), matches({ game: "bedwars", mode: "solo", beta: "true" })]; // [true, false]});parse fails with InvalidSelector and a message such as a requirement is missing after the last ",". format turns a selector back into its text form.
How Velocity finds its servers
Section titled “How Velocity finds its servers”Velocity keeps its server names: /server arena still works, and so do your proxy bundle’s proxy.getServer("lobby") calls. Behind each name, the proxy’s connector resolves a selector. A player moves between servers by their labels, over the connection they joined with:
mk server --network writes the proxy’s plugins/:
{ "relays": ["http://127.0.0.1:3340"], "directory": { "api": "http://localhost:4776" }, "labels": { "minekube.com/entry": "true" }, "servers": { "lobby": "stage=lobby", "arena": "game=arena" }}and each Paper server’s plugins/, here the lobby’s:
{ "relays": ["http://127.0.0.1:3340"], "directory": { "api": "http://localhost:4776" }, "labels": { "stage": "lobby" }}serversmaps each Velocity server name to a selector. The runtime registers every name with Velocity at a loopback port of the connector.- Each new connection to that port asks the registry for the selector, picks a ready instance with free slots, and opens a stream to it over iroh, connector to connector. The servers need no open port and may run on other hosts, behind NAT.
- A server that restarts under a new key is reachable again without any change, because its labels still match.
- Velocity still needs its
[servers]entries invelocity.tomlto start; the connector replaces them with its selector ports.
List instances
Section titled “List instances”mk instances lists a network’s instances with their labels, players and whether they are online. -l takes a selector, as kubectl -l does:
mk instances --network devmk instances --network dev -l stage=lobbymk instances --network dev -l 'minekube.com/platform=paper,game in (arena,duels)'Each line shows the start of the instance’s id, online or offline, players and slots, and its labels. Quote a selector with spaces or parentheses for your shell.
Add an instance to a network
Section titled “Add an instance to a network”An instance whose key belongs to no network logs a code of 8 characters, valid for 15 minutes; after that it logs a new one. Add it to your network with the code:
mk claim ABCD2345 --network devmk server --network adds its own instances to the dev network without a code. mk claim and mk instances talk to the Minekube API at MINEKUBE_API, or --api, by default the local one that mk api and mk server --network run on http://localhost:4776, with the token in MINEKUBE_DEV_TOKEN.
Was this helpful?
Thanks for the feedback.