Skip to content

Commit

Permalink
Merge pull request #22 from AzisabaNetwork/feat/version-2
Browse files Browse the repository at this point in the history
🔖 Version 2.0.0
  • Loading branch information
siloneco authored Oct 10, 2022
2 parents f1b0f19 + 2f8f4ae commit 6569672
Show file tree
Hide file tree
Showing 23 changed files with 898 additions and 770 deletions.
64 changes: 38 additions & 26 deletions README-JP.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# Kuvel

## 概要

Kubernetesクラスター内のMinecraftサーバーを監視し、Velocityに自動で反映するVelocity Plugin

## 機能

* Kubernetesクラスターの中にあるMinecraftのPodを監視し、自動でVelocityに登録/登録解除する
* LoadBalancerサーバーを作成し、そのサーバーに参加しようとしたプレイヤーを配下のサーバーに振り分ける
* Redisを使用して、複数のVelocityで名前を同期する

## 導入
Pluginは [Releases](https://github.com/AzisabaNetwork/Kuvel/releases/latest) からダウンロードできます。 `Kuvel.jar` をダウンロードしVelocityに導入してください。

Pluginは [Releases](https://github.com/AzisabaNetwork/Kuvel/releases/latest)
からダウンロードできます。 `Kuvel.jar` をダウンロードしVelocityに導入してください。ダウンロード後、コンフィグの設定を行ってください。

```yml
redis:
group-name: "production" # Redisサーバーが同じかつgroup-nameが同じサーバー間でのみ名前同期が行われます
connection:
hostname: "redis"
port: 6379
username: "default"
password: "password"
```
Kuvelがサーバーを監視するためには、Kubernetesに対して権限を要求しなければなりません。VelocityのPodに対してPodとReplicaSetのget/list/watchを許可してください
```yml
apiVersion: v1
kind: ServiceAccount
metadata:
name: velocity-account
namespace: default
---
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand Down Expand Up @@ -49,20 +65,21 @@ PodがMinecraftサーバーであることをKuvelに示すには、Kubernetes
|minecraftServerName|Velocityに登録したいサーバー名|

### Podの場合

```yml
apiVersion: v1
kind: Pod
metadata:
name: test-server
labels:
minecraftServiceDiscovery: "true" # KuvelがMinecraftサーバーを見つけるために必要
minecraftServerName: "test-server" # Kuvelがサーバーの命名をするために必要
kuvel.azisaba.net/enable-server-discovery: "true" # KuvelがMinecraftサーバーを見つけるために必要
kuvel.azisaba.net/preferred-server-name: "test-server" # Kuvelがサーバーの命名をするために必要
spec:
containers:
- name: test-server
image: itzg/minecraft-server:java8
ports:
- containerPort: 25565
- name: test-server
image: itzg/minecraft-server:java8
ports:
- containerPort: 25565
```
### Deploymentの場合
Expand All @@ -80,8 +97,8 @@ spec:
metadata:
labels:
app: test-server-deployment
minecraftServiceDiscovery: "true" # KuvelがMinecraftサーバーを見つけるために必要
minecraftServerName: "test-server" # Kuvelがサーバーの命名をするために必要
kuvel.azisaba.net/enable-server-discovery: "true" # KuvelがMinecraftサーバーを見つけるために必要
kuvel.azisaba.net/preferred-server-name: "test-server" # Kuvelがサーバーの命名をするために必要
spec:
containers:
- name: test-server
Expand All @@ -96,14 +113,15 @@ spec:

## ロードバランサー
Lobby等の並列化可能なサーバーにおいて、出来る限り人数を分散したいことがあります。その時にKuvelのLoadBalancer機能が役に立ちます

```yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: lobby-deployment
labels:
minecraftServiceDiscovery: "true"
minecraftServerName: "lobby"
kuvel.azisaba.net/enable-server-discovery: "true"
kuvel.azisaba.net/preferred-server-name: "lobby"
spec:
replicas: 3
selector:
Expand All @@ -113,15 +131,16 @@ spec:
metadata:
labels:
app: lobby-deployment
minecraftServiceDiscovery: "true"
minecraftServerName: "lobby"
kuvel.azisaba.net/enable-server-discovery: "true"
kuvel.azisaba.net/preferred-server-name: "lobby"
spec:
containers:
- name: lobby
image: itzg/minecraft-server:java8
ports:
- containerPort: 25565
```

Deploymentに対してLabelを適用することで、KuvelのLoadBalancer機能を有効化することができます。KuvelのLoadBalancerは以下の機能を有しています

1. ReplicaSet配下のPodに対し、ランダムに接続先を振り分けて転送する
Expand All @@ -130,19 +149,12 @@ Deploymentに対してLabelを適用することで、KuvelのLoadBalancer機能
これを用いることにより、`/server lobby` を実行したときに `lobby-1`, `lobby-2`, `lobby-3`の中からランダムに接続するといった仕組みを実装できます

## 複数Velocityでサーバー名を同期する
Kubernetesクラスター内ではPodがほぼ同時に作成されることがある等の理由により、まれにVelocityによってサーバーの登録名が違うといった事が起こりえます。Velocityを並列化している環境では、この現象は致命的な問題を引き起こします。Kuvelはそれを回避するため、Redisによるサーバー名同期を実現しています。

この機能を有効化するには、config.ymlで`redis.enable`を`true`に設定するだけです。Kuvelはキー名が `kuvel:` から始まるキーを使用します。
```yml
redis:
enable: true # trueにすることによりRedisによるサーバー名同期が有効化されます
group-name: "production" # Redisサーバーが同じかつgroup-nameが同じサーバー間でのみ名前同期が行われます
connection:
hostname: "localhost"
port: 6379
username: "root"
password: "password"
```
Kubernetesクラスター内ではPodがほぼ同時に作成されることがある等の理由により、まれにVelocityによってサーバーの登録名が違うといった事が起こりえます。Velocityを並列化している環境では、この現象は致命的な問題を引き起こします。Kuvelはそれを回避するため、Redisによるサーバー名同期を実現しています。Kuvelはキー名が `kuvel:`
から始まるキーを使用します。

1.xではこの機能の有効化は任意でしたが、2.0.0以降デフォルトで有効になりました。

## ライセンス

[GNU General Public License v3.0](LICENSE)
76 changes: 47 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
# Kuvel
## Overview
Kuvel, A service discovery plugin for Velocity. It will automatically discover Minecraft servers and register/unregister them in Velocity.
Kuvel, A service discovery plugin for Velocity. It will automatically discover Minecraft servers and
register/unregister them in Velocity.

## Features

* Monitor Minecraft pods in a Kubernetes cluster and automatically register/unregister them with Velocity
* Monitor Minecraft pods in a Kubernetes cluster and automatically register/unregister them with
Velocity
* Create a LoadBalancer server and distribute players trying to join to the linked servers.
* Synchronize server names across multiple Velocity servers using Redis

## Installing

The Plugin can be downloaded from [Releases](https://github.com/AzisabaNetwork/Kuvel/releases/latest). Download `Kuvel.jar` and install it into Velocity.
The Plugin can be downloaded
from [Releases](https://github.com/AzisabaNetwork/Kuvel/releases/latest). Download `Kuvel.jar` and
install it into Velocity plugins directory. Also, you have to fill in the configuration file.

```yml
# Server name synchronization by Redis is required in load-balanced environments using multiple Velocity.
redis:
group-name: "production"
connection:
hostname: "redis"
port: 6379
# username is optional. if you have authentication enabled, you can use it here. Or leave it blank or null.
username: "default"
# password is optional. if you have authentication enabled, you can use it here. Or leave it blank or null.
password: "password"
```
In order for Kuvel to monitor the server, you must request permission from Kubernetes to allow
Velocity pods discovery Minecraft servers. For Velocity pods, please allow get/list/watch to Pods
and ReplicaSets.
In order for Kuvel to monitor the server, you must request permission from Kubernetes to allow Velocity pods discovery Minecraft servers. For Velocity pods, please allow get/list/watch to Pods and ReplicaSets.
```yml
apiVersion: v1
kind: ServiceAccount
metadata:
name: velocity-account
namespace: default
---
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand Down Expand Up @@ -51,20 +71,22 @@ To tell Kuvel that the pod is a Minecraft server, use Label feature of Kubernete
|minecraftServerName|Name of the server you wish to register with Velocity|

### Pod

```yml
apiVersion: v1
kind: Pod
metadata:
name: test-server
labels:
minecraftServiceDiscovery: "true" # Required for Kuvel to detect Minecraft servers.
minecraftServerName: "test-server" # Required for Kuvel to name the server
kuvel.azisaba.net/enable-server-discovery: "true" # Required for Kuvel to detect Minecraft servers.
kuvel.azisaba.net/preferred-server-name: : "test-server" # Required for Kuvel to name the server
# kuvel.azisaba.net/initial-server: "true" # Uncomment out this line if you want to make this server the initial server.
spec:
containers:
- name: test-server
image: itzg/minecraft-server:java8
ports:
- containerPort: 25565
- name: test-server
image: itzg/minecraft-server:java8
ports:
- containerPort: 25565
```
### Deployment
Expand All @@ -82,8 +104,9 @@ spec:
metadata:
labels:
app: test-server-deployment
minecraftServiceDiscovery: "true" # Required for Kuvel to detect Minecraft servers.
minecraftServerName: "test-server" # Required for Kuvel to name the server
kuvel.azisaba.net/enable-server-discovery: "true" # Required for Kuvel to detect Minecraft servers.
kuvel.azisaba.net/preferred-server-name: "test-server" # Required for Kuvel to name the server
# kuvel.azisaba.net/initial-server: "true" # Uncomment out this line if you want to make this server the initial server.
spec:
containers:
- name: test-server
Expand All @@ -106,8 +129,9 @@ kind: Deployment
metadata:
name: lobby-deployment
labels:
minecraftServiceDiscovery: "true"
minecraftServerName: "lobby"
kuvel.azisaba.net/enable-server-discovery: "true"
kuvel.azisaba.net/preferred-server-name: "lobby"
# kuvel.azisaba.net/initial-server: "true" # Uncomment out this line if you want to make this load balancer server the initial server.
spec:
replicas: 3
selector:
Expand All @@ -117,8 +141,9 @@ spec:
metadata:
labels:
app: lobby-deployment
minecraftServiceDiscovery: "true"
minecraftServerName: "lobby"
kuvel.azisaba.net/enable-server-discovery: "true"
kuvel.azisaba.net/preferred-server-name: "lobby"
# kuvel.azisaba.net/initial-server: "true" # Uncomment out this line if you want to make this server the initial server.
spec:
containers:
- name: lobby
Expand All @@ -136,19 +161,12 @@ Using this, you can implement a mechanism to randomly connect to `lobby-1`, `lob

## Synchronize Server Names in Multi Velocity Environment

In a Kubernetes cluster, pods can be created at almost the same time, and this can cause a fatal problem in a parallel Velocity environment because it is possible that different Velocity servers have different registration names. Kuvel provides name synchronization using Redis to avoid this problem.
In a Kubernetes cluster, pods can be created at almost the same time, and this can cause a fatal
problem in a parallel Velocity environment because it is possible that different Velocity servers
have different registration names. Kuvel provides name synchronization using Redis to avoid this
issue. Kuvel uses keys whose key name begins with `kuvel:`.

To enable this feature, simply set `redis.enable` to `true` in config.yml. Kuvel uses keys whose key name begins with `kuvel:`.
```yml
redis:
enable: true # Setting it to true enables server name synchronization using Redis
group-name: "production" # Name synchronization is performed only between servers with the same Redis server and the same group-name
connection:
hostname: "localhost"
port: 6379
username: "root"
password: "password"
```
On 1.x, this feature was optional, but since 2.0.0, this setting became enabled by default.

## License
[GNU General Public License v3.0](LICENSE)
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.azisaba</groupId>
<artifactId>Kuvel</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>6.1.1</version>
<version>5.12.4</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
Expand Down
Loading

0 comments on commit 6569672

Please sign in to comment.