# Networks

> A Minekube network is a name players join and the servers that belong to it, wherever they run: owned by a Minecraft account, joined only with consent, closed to everyone outside it, and addressed by labels instead of IP addresses.

> **Preview: Connect in the Minekube plugin:**
> This page describes networks in the Minekube plugin, the next generation of Connect. Today's Connect plugin and its `<endpoint>.play.minekube.net` addresses are described in the [Connect docs](https://minekube.com/guide/) and keep working. [Networks in the Minekube plugin](https://minekube.com/guide/networks/) compares the two.

A Minekube network is a name players join, plus the servers and proxies that belong to it, wherever they run. A Paper server at home behind NAT, a proxy on a VPS and a game server in a Kubernetes cluster can all be members of one network. Players type one address, and the network decides where they go.

The network is the unit everything else in Connect hangs on. The registry stores it, the relays route to it, and Games deploys code to it.

## What a network is

- **A name.** Lowercase letters, digits and hyphens, unique in the registry. Players join `<name>.g.minekube.net` in production; during the preview, the Minekube API and relay run on staging, and players join `<name>.staging.minekube.net`.
- **An owner.** The Minecraft account that created the network. See [Accounts](https://minekube.com/guide/networks/concepts/account).
- **Members.** Each member is an [instance](https://minekube.com/guide/networks/concepts/instance): a server or proxy, identified by a key it made itself.
- **Entry instances.** The members labelled `minekube.com/entry=true`, where players land when they type the network's address.
- **Deployments.** Which version of which bundles runs on which members, picked by labels.
- **An issuer.** Every network is an OpenID Connect issuer that publishes its members' keys.

A network is data in the registry: its name and address, its owner, its members, its entry, and its deployments. It is not a program, not a machine and not a proxy, and it runs no process of its own. Proxies, like servers, are members.

## Why networks exist

With today's Connect, each server is its own endpoint with its own address. A group of servers that should feel like one place needs a proxy in front, and that proxy must reach every backend directly, on one host or through open ports.

A network makes the group the unit instead. Players get one address. The members connect outward to Minekube's relays and to each other, so they can run anywhere, and none of them needs an open port. Code names members by what they are, not where they are.

## Owned by an account

The account that creates a network owns it. A Minekube account is a Minecraft: Java Edition account, so there is no separate sign-up.

- **The owner manages the network:** it lets servers in, keeps trust rules, lists the members and deploys code to them.
- **A network has one owner.** There are no other roles today.
- **Some names are kept.** Names that Minekube's own hosts use, such as `play` and `relay`, and names such as `api`, cannot be taken by an account.

## Members join with consent

A member is an instance whose key the registry has put into the network. Joining takes consent from both sides, because a key alone is public, and because the owner of a network runs code on its members through deployments.

- **The owner agrees** by making an invite, keeping a trust rule, or claiming a code.
- **The server agrees** by showing something only it has: that invite, a token from its environment that a trust rule covers, or the code it logged.
- **A key belongs to one network at a time.** When it joins another network, it leaves the first.
- **Membership survives restarts.** A key that is in the network stays in it.

[Joining with consent](https://minekube.com/guide/networks/concepts/joining) explains each way in.

## The network is a boundary

Minekube fixes one rule and leaves the others to the network: a connector accepts player streams only from Minekube's relays and from instances of its own network. Without that rule, no rule a network writes for itself would be safe.

- **Outsiders cannot reach a member directly.** An instance of another network, or a key that belongs to no network, is refused.
- **Members see only their own network.** When an instance looks up other instances or fetches bundles, the registry answers within its network.
- **Labels grant no rights.** An instance chooses its own labels, but only its key decides which network it belongs to.

## Entry instances

When a player types the network's address, the relay sends them to an entry instance: an online member labelled `minekube.com/entry=true` that takes players. In a network with Velocity, the proxy is the entry instance. In a network of Paper servers alone, each server that players may join first is one.

You set the label in the instance's `connector.json`; it is the only label under `minekube.com/` that an instance may set itself. When no entry instance is online, the relay shows the network as offline in the server list and turns joins away with a message.

[Entry and routing](https://minekube.com/guide/networks/concepts/entry-and-routing) explains how the relay picks one.

## Labels instead of addresses

Inside a network, code and configuration name servers by [label selectors](https://minekube.com/guide/networks/labels), such as `stage=lobby`, never by IP address, port or key.

- **A server can change underneath.** It can restart under a new key, move to another host or sit behind NAT, and the selector still finds it.
- **Velocity keeps its server names.** Each name resolves to a selector, so `/server arena` and a proxy bundle's `getServer("lobby")` keep working.
- **The same selectors pick everywhere:** which server a player goes to, which servers a deployment reaches, and what a list of instances shows.

## Versions and deployments per network

Each network keeps its own [versions and deployments](https://minekube.com/games/concepts/versions-and-deployments). A version is an immutable, content-addressed set of bundles. A deployment assigns a version to a label selector of the network. Every member whose labels match runs its bundles, and a member that starts later gets them by itself.

The bundles are stored by their hash, and only members of the network can fetch them. [Versions and deployments](https://minekube.com/games/versions-and-deployments/) shows how to work with them.

## Every network is an OpenID Connect issuer

A member's identity should be checkable outside Minekube, with standard tools and without asking Minekube. So the Minekube API hosts every network as an [OpenID Connect](https://openid.net/connect/) issuer at `https://<api>/n/<network>`:

- **Its key set lists the members' public keys,** each with its instance ID as `kid`. A token that a member signs with its own key can be checked by anyone with a JWT library, for as long as the member belongs to the network.
- **It trusts other issuers in return.** A trust rule lets a server join with the token its environment already gives it, such as a Kubernetes service account token.

[Connector, relay and API](https://minekube.com/guide/networks/connectivity#every-network-is-an-openid-connect-issuer) describes the issuer in detail.

## Network shapes

Because a network is data and its members are found by label, it takes whatever shape suits it. Each member that players may enter through carries the entry label.

| Shape | Entry | Status |
| --- | --- | --- |
| **One server** | The Paper server itself | Built |
| **A proxy and servers** | The Velocity proxy, which finds its servers by label, on any host | Built |
| **Several servers without a proxy** | Each server players may enter through. Moving players between them by a transfer through Minekube host names is planned. | Entry built; transfer planned |
| **Several proxies,** for example one per region | Each proxy. The relay picks among them by free slots today. | Built |

[Networks by design](https://minekube.com/guide/networks/network-model#network-shapes) weighs the shapes against each other.

## Where a network's logic runs

A network has no code of its own to run; its members run code, and each kind runs where it belongs.

| Code | Runs on | Status |
| --- | --- | --- |
| **Game bundles** | The Paper servers a deployment's selector matches, next to the world | Built |
| **Proxy bundles** | The proxies a deployment's selector matches, such as `role=proxy`, so a network with several proxies runs the same code on each. See [Bundles](https://minekube.com/games/concepts/bundle). | Built, on Velocity |
| **A routing bundle** | Cloudflare, answering "where does this player go?" as data that the relay caches | Planned. See [Entry and routing](https://minekube.com/guide/networks/concepts/entry-and-routing#the-planned-routing-question) |

## Like a zone on Cloudflare

If you know Cloudflare, the model will look familiar:

| Cloudflare | Minekube |
| --- | --- |
| A zone | A network |
| Origins, connected by Cloudflare Tunnel | Members, connected by the connector |
| The edge | The relays |
| A Worker on a route | A routing bundle (planned) |

The difference is where the code runs. Game code runs where the world is, on your servers, in the same tick as the game.

## A player's path

A player types the network's address, and their connection passes through a relay to an entry instance. What happens next depends on the network's shape.

**With Velocity**, the proxy is the entry instance, and it reaches its backends through the connector:

```text
 player types my-network.g.minekube.net
        │
        ▼
 ┌─────────┐  entry instances of my-network?   ┌──────────┐
 │  relay  │ ────────────────────────────────▶ │ registry │
 │         │ ◀──── online, labelled entry ──── │          │
 └────┬────┘       (cached in the relay)       └──────────┘
      │ stream to the entry's connector
      ▼
 ┌─────────────────────────────┐
 │ Velocity + Minekube plugin  │  logs the player in
 │ minekube.com/entry=true     │  "lobby" means stage=lobby
 └────┬────────────────────────┘
      │ stream from connector to connector, picked by labels
      ▼
 ┌─────────────────────────────┐
 │ Paper + Minekube plugin     │  may run on another host,
 │ stage=lobby                 │  behind NAT
 └─────────────────────────────┘
```

**Without Velocity**, a Paper server is the entry instance and logs the player in itself:

```text
 player types my-network.g.minekube.net
        │
        ▼
 ┌─────────┐  entry instances of my-network?   ┌──────────┐
 │  relay  │ ◀───────────────────────────────▶ │ registry │
 └────┬────┘                                   └──────────┘
      │ stream to the entry's connector
      ▼
 ┌─────────────────────────────┐
 │ Paper + Minekube plugin     │  logs the player in
 │ minekube.com/entry=true     │
 └─────────────────────────────┘
```

In words:

1. The player's client opens a connection to the relay and sends a handshake with the address it typed.
2. The relay reads the network's name from that address and asks the registry for the network's online entry instances. It caches the answer.
3. The relay picks an entry instance that takes players and opens a stream to its connector. From then on, it only copies bytes.
4. The entry instance logs the player in. With Velocity, the proxy then sends the player to a backend: each server name stands for a label selector, and the proxy's connector opens a stream to a matching server.
5. Without Velocity, the player stays on the Paper server they entered.

## What is and is not a network

The word means different things in different places. On this site, "network" alone means a Minekube network.

| Term | What it is |
| --- | --- |
| **A Minekube network** | Data in the registry, described on this page: a name and address, an owner, members, an entry, deployments. Not a program and not a proxy. |
| **A proxy bundle** | Effect TypeScript code that runs on a network's proxies, Velocity today, such as `/lobby` and where kicked players go. A network can have one proxy, several or none. [Proxy bundles](https://minekube.com/games/write/proxy-bundles) shows how to write one. |
| **A Velocity network** | A Velocity proxy and its backend servers, the classic Minecraft setup. Inside a Minekube network it is one shape: the proxy is a member and the entry, and it finds the other members by label. |
| **A Connect endpoint** | Today's Connect: one server's public address, `<endpoint>.play.minekube.net`, from the Connect plugin or Gate. See [Connect](https://minekube.com/guide/). An endpoint is not a Minekube network. |

The dev network that `mk server --network` runs on your machine is a Minekube network named `dev`, with a local Minekube API and relay, and Velocity in front of two Paper servers. See [Run the dev network](https://minekube.com/games/local-development/dev-network).

## Built and planned

| Part | Status |
| --- | --- |
| Networks with an owner, members by key, consent to join, the network boundary, entry instances, labels and selectors, deployments, the OpenID Connect issuer | Built, in preview on staging |
| Production at `<network>.g.minekube.net`, with relays in several regions | Planned next |
| Hostnames under a network, such as `arena.my-network.g.minekube.net`, and custom domains | Planned |
| One routing question that a network answers in code, a waiting room in the relay, and signed origins between instances | Planned. See [Entry and routing](https://minekube.com/guide/networks/concepts/entry-and-routing) |
| Tokens for players and a signing key of the network's own | Planned |

## Related

- [Create a network](https://minekube.com/guide/networks/create-a-network): log in and make one.
- [Let servers in](https://minekube.com/guide/networks/let-servers-in): add members with an invite or a trust rule.
- [Networks by design](https://minekube.com/guide/networks/network-model): the design behind networks, with network shapes.
