diff options
Diffstat (limited to 'simulation/kubernetes')
-rw-r--r-- | simulation/kubernetes/Dockerfile | 15 | ||||
-rw-r--r-- | simulation/kubernetes/config.toml.in | 13 | ||||
-rwxr-xr-x | simulation/kubernetes/entrypoint.sh | 7 | ||||
-rw-r--r-- | simulation/kubernetes/peer-server.yaml | 51 | ||||
-rwxr-xr-x | simulation/kubernetes/run_simulation.sh | 41 | ||||
-rw-r--r-- | simulation/kubernetes/validator.yaml.in | 38 |
6 files changed, 165 insertions, 0 deletions
diff --git a/simulation/kubernetes/Dockerfile b/simulation/kubernetes/Dockerfile new file mode 100644 index 0000000..c6599d8 --- /dev/null +++ b/simulation/kubernetes/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:alpine +MAINTAINER Wei-Ning Huang <w@dexon.org> + +# Cobinhood vendor base directory. +RUN mkdir -p /opt/dexon/ + +# Copy data. +COPY build/dexcon-simulation /opt/dexon +COPY build/dexcon-simulation-peer-server /opt/dexon +COPY entrypoint.sh /opt/dexon +COPY config.toml /opt/dexon + +WORKDIR /opt/dexon + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/simulation/kubernetes/config.toml.in b/simulation/kubernetes/config.toml.in new file mode 100644 index 0000000..d956055 --- /dev/null +++ b/simulation/kubernetes/config.toml.in @@ -0,0 +1,13 @@ +title = "DEXON Consensus Simulation Config" + +[validator] +num = {{numValidators}} +propose_interval_mean = 5e+02 +propose_interval_sigma = 3e+01 + +[networking] +type = "tcp" +peer_server = "peer-server-svc.default.svc.cluster.local" +mean = 1e+02 +sigma = 1e+01 +loss_rate_value = 0e+00 diff --git a/simulation/kubernetes/entrypoint.sh b/simulation/kubernetes/entrypoint.sh new file mode 100755 index 0000000..a892580 --- /dev/null +++ b/simulation/kubernetes/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ "$ROLE" = "validator" ]; then + exec ./dexcon-simulation -config config.toml +elif [ "$ROLE" = "peer-server" ]; then + exec ./dexcon-simulation-peer-server -config config.toml +fi diff --git a/simulation/kubernetes/peer-server.yaml b/simulation/kubernetes/peer-server.yaml new file mode 100644 index 0000000..360736b --- /dev/null +++ b/simulation/kubernetes/peer-server.yaml @@ -0,0 +1,51 @@ +apiVersion: v1 +kind: Service +metadata: + name: peer-server-svc + labels: + app: peer-server-svc +spec: + selector: + app: dexcon-simulation-peer-server + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: dexcon-simulation-peer-server + labels: + app: dexcon-simulation-peer-server +spec: + revisionHistoryLimit: 5 + replicas: 1 + template: + metadata: + name: dexcon-simulation-peer-server + labels: + app: dexcon-simulation-peer-server + spec: + nodeSelector: + cloud.google.com/gke-nodepool: default-pool + volumes: + - name: ssl-certs + hostPath: + path: /etc/ssl/certs + containers: + - name: dexcon-simulation + image: asia.gcr.io/cobinhood/dexcon-simulation:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + cpu: 100m + memory: 256Mi + limits: + cpu: 200m + memory: 512Mi + env: + - name: ROLE + value: "peer-server" diff --git a/simulation/kubernetes/run_simulation.sh b/simulation/kubernetes/run_simulation.sh new file mode 100755 index 0000000..88f9eee --- /dev/null +++ b/simulation/kubernetes/run_simulation.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +IMAGE_TAG=asia.gcr.io/cobinhood/dexcon-simulation:latest + + +build_binary() { + make DOCKER=true -C ../.. + cp -r ../../build . +} + +build_docker_image() { + docker build -t ${IMAGE_TAG} . + docker push ${IMAGE_TAG} +} + +start_simulation() { + kubectl delete deployment --all --force --grace-period=0 + sleep 10 + + kubectl apply -f peer-server.yaml + sleep 10 + kubectl apply -f validator.yaml +} + +main() { + local num_validators=$1 + + if [ "$num_validators" == "" ]; then + num_validators=7 + fi + + # Render configuration files. + sed "s/{{numValidators}}/$num_validators/" validator.yaml.in > validator.yaml + sed "s/{{numValidators}}/$num_validators/" config.toml.in > config.toml + + build_binary + build_docker_image + start_simulation +} + +main $* diff --git a/simulation/kubernetes/validator.yaml.in b/simulation/kubernetes/validator.yaml.in new file mode 100644 index 0000000..8c0dd1d --- /dev/null +++ b/simulation/kubernetes/validator.yaml.in @@ -0,0 +1,38 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: dexcon-simulation + labels: + app: dexcon-simulation + type: cobinhood +spec: + revisionHistoryLimit: 5 + replicas: {{numValidators}} + template: + metadata: + name: dexcon-simulation + labels: + app: dexcon-simulation + spec: + nodeSelector: + cloud.google.com/gke-nodepool: default-pool + volumes: + - name: ssl-certs + hostPath: + path: /etc/ssl/certs + containers: + - name: dexcon-simulation + image: asia.gcr.io/cobinhood/dexcon-simulation:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + cpu: 100m + memory: 256Mi + limits: + cpu: 200m + memory: 512Mi + env: + - name: ROLE + value: "validator" |