# Let servers in

> Add a server to your Minekube network with consent on both sides - your dev server with one flag, any server with a one-time invite, or every server of a Kubernetes cluster or CI system with a trust rule.

> **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 server belongs to a network by its key. On its first start, the connector in the Minekube plugin makes a key in the plugin folder, and from then on the key is the server's identity. A server needs no open port, because players reach it through Minekube's relays.

## Choose a way in

A network owner adds a server in one of three ways, each with the server's consent:

| Way | When | How |
| --- | --- | --- |
| **Your dev server** | To play your game with friends from your machine | `mk server --join my-network` |
| **An invite** | A plain VPS, a hosting panel, a cluster without a public token issuer | `mk network invite my-network`, then put the token in a file the server's `connector.json` names |
| **A trust rule** | A Kubernetes cluster or CI with OpenID Connect tokens | `mk trust add --network my-network --issuer <url> --subject <sub>`; each server joins with the token its environment gives it |

An owner cannot add a server's key without the server, because a key alone is public. The code a new server logs while it belongs to no network (`mk claim <code> --network my-network`) works too.

### Your dev server

```sh
mk server --join my-network
```

`mk` makes an invite for the dev server, points its connector at the registry and relay, and turns on online mode, because anyone can reach the server now. Players join `my-network.<domain>`. `mk server` without `--join` makes it private again.

### With an invite

```sh
mk network invite my-network --labels game=parkour
```

It prints a one-time token, valid for an hour (`--hours`, up to a week). On the server, write it to a file and name it in `plugins/Minekube/connector.json`:

```json
{
  "directory": { "registry": "https://registry.staging.minekube.net" },
  "relays": ["https://relay.staging.minekube.net/"],
  "join": { "network": "my-network", "token": "network-invite" }
}
```

The server shows the invite once. After that its key is in the network, and a restart keeps it there. `--labels` gives every server the invite lets in these labels, over its own. A network holds at most 100 unused invites.

### With a trust rule

A server in Kubernetes already has a token from its environment: a projected service account token. A trust rule lets every server whose token matches join without an invite:

```sh
mk trust add --network my-network --issuer https://kubernetes.example --subject system:serviceaccount:games: --prefix --audience minekube --labels game=parkour
```

In `connector.json`, `"join": {"network": "my-network", "token": "/var/run/secrets/minekube/token"}` names the token file. The registry checks the token against the issuer's published keys; no Minekube secret is stored on the server. [Connector, relay and registry](https://minekube.com/guide/networks/connectivity#every-network-is-an-openid-connect-issuer) explains how.

## Check the servers

`mk instances --network my-network` lists the servers, with their labels and whether they are online.

The [connector.json reference](https://minekube.com/guide/networks/connector-json) lists every field of the file.

## Related

- [Labels and selectors](https://minekube.com/guide/networks/labels): the labels a server gets, and how a network picks servers by them.
- [Connector, relay and registry](https://minekube.com/guide/networks/connectivity#every-network-is-an-openid-connect-issuer): how a trust rule checks a token.
