-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add Shard Cluster Mode PoC for docker
- Loading branch information
Showing
8 changed files
with
1,862 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Yorkie Shard Cluster Docker PoC | ||
|
||
> Warning: You need to put API Key in Yorkie Client to see proper routing!!! | ||
## Architecture | ||
|
||
- Router | ||
- envoy: router/proxy which performs ring hash algorithm based routing based on x-api-key (project_id) | ||
- Server | ||
- yorkie1, yorkie2, yorkie3: normal yorkie server with 3 replica. They do **NOT** communicate with each other as previous broadcasting based cluster mode | ||
- Database | ||
- mongo: stand-alone mongoDB. mongoDB with shard will be implemented soon (yorkie server's mongo client needs some shard related changes to use mongoDB shard) | ||
|
||
## Getting Started | ||
|
||
### Step 1. Deploy | ||
|
||
Deploy docker based servers using docker-compose: | ||
|
||
``` | ||
docker-compose up --build -d | ||
``` | ||
|
||
### Step 2. Get public API key | ||
|
||
API Key is **essential** to perform api key based routing: | ||
|
||
``` | ||
git clone https://github.com/yorkie-team/dashboard.git | ||
npm install | ||
npm run start | ||
get API key | ||
``` | ||
|
||
### Step 3. Use any Yorkie implemented examples | ||
|
||
Test with any Yorkie implemented examples: | ||
|
||
``` | ||
git clone https://github.com/krapie/yorkie-tldraw | ||
put API Key in `REACT_APP_YORKIE_API_KEY` in `.env.Production` | ||
yarn | ||
yarn start | ||
``` | ||
|
||
### Step 4. Check routing behavior | ||
|
||
Check routing behavior by watching docker logs: | ||
|
||
``` | ||
docker compose logs | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
version: "3.3" | ||
|
||
services: | ||
envoy: | ||
build: | ||
context: ./ | ||
dockerfile: ./envoy.Dockerfile | ||
image: "grpcweb:envoy" | ||
container_name: "envoy" | ||
restart: always | ||
ports: | ||
- "8080:8080" | ||
- "9090:9090" | ||
- "9901:9901" | ||
command: ["/etc/envoy/envoy.yaml"] | ||
depends_on: | ||
- yorkie1 | ||
- yorkie2 | ||
- yorkie3 | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
|
||
yorkie1: | ||
image: "yorkieteam/yorkie:latest" | ||
container_name: "yorkie1" | ||
command: | ||
[ | ||
"server", | ||
"--mongo-connection-uri", | ||
"mongodb://mongo:27017", | ||
"--enable-pprof", | ||
] | ||
restart: always | ||
ports: | ||
- "11101:11101" | ||
- "11102:11102" | ||
- "11103:11103" | ||
depends_on: | ||
- mongo | ||
|
||
yorkie2: | ||
image: "yorkieteam/yorkie:latest" | ||
container_name: "yorkie2" | ||
command: | ||
[ | ||
"server", | ||
"--mongo-connection-uri", | ||
"mongodb://mongo:27017", | ||
"--enable-pprof", | ||
] | ||
restart: always | ||
ports: | ||
- "11201:11101" | ||
- "11202:11102" | ||
- "11203:11103" | ||
depends_on: | ||
- mongo | ||
|
||
yorkie3: | ||
image: "yorkieteam/yorkie:latest" | ||
container_name: "yorkie3" | ||
command: | ||
[ | ||
"server", | ||
"--mongo-connection-uri", | ||
"mongodb://mongo:27017", | ||
"--enable-pprof", | ||
] | ||
restart: always | ||
ports: | ||
- "11301:11101" | ||
- "11302:11102" | ||
- "11303:11103" | ||
depends_on: | ||
- mongo | ||
|
||
mongo: | ||
image: mongo:latest | ||
container_name: mongo | ||
restart: always | ||
ports: | ||
- "27017:27017" |
127 changes: 127 additions & 0 deletions
127
docker/yorkie-shard-cluster-docker/envoy-ring-hash-router.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
admin: | ||
access_log_path: /tmp/admin_access.log | ||
address: | ||
socket_address: { address: 0.0.0.0, port_value: 9901 } | ||
|
||
static_resources: | ||
listeners: | ||
- name: yorkie_listener | ||
address: | ||
socket_address: { address: 0.0.0.0, port_value: 8080 } | ||
filter_chains: | ||
- filters: | ||
- name: envoy.filters.network.http_connection_manager | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager | ||
stat_prefix: ingress_http | ||
route_config: | ||
name: yorkie_ring_hash_routes | ||
virtual_hosts: | ||
- name: yorkie_service | ||
domains: ["*"] | ||
routes: | ||
- match: { prefix: "/" } | ||
route: | ||
cluster: yorkie_service | ||
hash_policy: | ||
header: | ||
header_name: x-api-key | ||
# https://github.com/grpc/grpc-web/issues/361 | ||
max_stream_duration: | ||
grpc_timeout_header_max: 0s | ||
cors: | ||
allow_origin_string_match: | ||
- prefix: "*" | ||
allow_methods: GET, PUT, DELETE, POST, OPTIONS | ||
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout,authorization,x-api-key | ||
max_age: "1728000" | ||
expose_headers: custom-header-1,grpc-status,grpc-message, grpc-status-details-bin | ||
http_filters: | ||
- name: envoy.filters.http.grpc_web | ||
- name: envoy.filters.http.cors | ||
- name: envoy.filters.http.router | ||
- name: admin_listener | ||
address: | ||
socket_address: { address: 0.0.0.0, port_value: 9090 } | ||
filter_chains: | ||
- filters: | ||
- name: envoy.filters.network.http_connection_manager | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager | ||
stat_prefix: ingress_http | ||
route_config: | ||
name: yorkie_ring_hash_routes | ||
virtual_hosts: | ||
- name: yorkie_service | ||
domains: ["*"] | ||
routes: | ||
- match: { prefix: "/" } | ||
route: | ||
cluster: admin_service | ||
# https://github.com/grpc/grpc-web/issues/361 | ||
max_stream_duration: | ||
grpc_timeout_header_max: 0s | ||
cors: | ||
allow_origin_string_match: | ||
- prefix: "*" | ||
allow_methods: GET, PUT, DELETE, POST, OPTIONS | ||
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout,authorization,x-api-key | ||
max_age: "1728000" | ||
expose_headers: custom-header-1,grpc-status,grpc-message, grpc-status-details-bin | ||
http_filters: | ||
- name: envoy.filters.http.grpc_web | ||
- name: envoy.filters.http.cors | ||
- name: envoy.filters.http.router | ||
clusters: | ||
- name: yorkie_service | ||
connect_timeout: 0.25s | ||
type: strict_dns | ||
http2_protocol_options: {} | ||
lb_policy: ring_hash | ||
ring_hash_lb_config: | ||
minimum_ring_size: 125 | ||
load_assignment: | ||
cluster_name: yorkie_cluster | ||
endpoints: | ||
- lb_endpoints: | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: host.docker.internal | ||
port_value: 11101 | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: host.docker.internal | ||
port_value: 11201 | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: host.docker.internal | ||
port_value: 11301 | ||
- name: admin_service | ||
connect_timeout: 0.25s | ||
type: strict_dns | ||
http2_protocol_options: {} | ||
lb_policy: ring_hash | ||
ring_hash_lb_config: | ||
minimum_ring_size: 125 | ||
load_assignment: | ||
cluster_name: admin_cluster | ||
endpoints: | ||
- lb_endpoints: | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: host.docker.internal | ||
port_value: 11103 | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: host.docker.internal | ||
port_value: 11203 | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: host.docker.internal | ||
port_value: 11303 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM envoyproxy/envoy:v1.19.0 | ||
|
||
COPY ./envoy-ring-hash-router.yaml /etc/envoy/envoy.yaml | ||
|
||
ENTRYPOINT ["/usr/local/bin/envoy", "-c"] | ||
|
||
CMD /etc/envoy/envoy.yaml |
73 changes: 73 additions & 0 deletions
73
docker/yorkie-shard-cluster-docker/mongodb-shard-docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
version: "3.7" | ||
|
||
services: | ||
config: | ||
image: mongo | ||
container_name: config | ||
command: mongod --configsvr --replSet configRS --bind_ip_all | ||
ports: | ||
- 27019:27019 | ||
networks: | ||
- mongo | ||
volumes: | ||
- config:/data/db | ||
|
||
shard1: | ||
image: mongo | ||
container_name: shard1 | ||
command: mongod --shardsvr --replSet shard1RS --bind_ip_all | ||
ports: | ||
- 27017:27017 | ||
networks: | ||
- mongo | ||
volumes: | ||
- shard1:/data/db | ||
|
||
shard2: | ||
image: mongo | ||
container_name: shard2 | ||
command: mongod --shardsvr --replSet shard2RS --bind_ip_all | ||
ports: | ||
- 27018:27017 | ||
networks: | ||
- mongo | ||
volumes: | ||
- shard2:/data/db | ||
|
||
shard3: | ||
image: mongo | ||
container_name: shard3 | ||
command: mongod --shardsvr --replSet shard3RS --bind_ip_all | ||
ports: | ||
- 27016:27017 | ||
networks: | ||
- mongo | ||
volumes: | ||
- shard3:/data/db | ||
|
||
mongos1: | ||
image: mongo | ||
container_name: mongos1 | ||
command: mongos --configdb configRS/config:27019 --bind_ip_all | ||
ports: | ||
- 27020:27017 | ||
networks: | ||
- mongo | ||
|
||
mongos2: | ||
image: mongo | ||
container_name: mongos2 | ||
command: mongos --configdb configRS/config:27019 --bind_ip_all | ||
ports: | ||
- 27021:27017 | ||
networks: | ||
- mongo | ||
|
||
volumes: | ||
config: | ||
shard1: | ||
shard2: | ||
shard3: | ||
|
||
networks: | ||
mongo: |
Oops, something went wrong.