From 230cf66135e7797e70de9fc5eddce00c6f0cb7a2 Mon Sep 17 00:00:00 2001 From: Alex Vorona Date: Fri, 26 Jun 2020 10:25:01 +0300 Subject: [PATCH 1/5] [parity] use sh instead of bash in health check to use with openethereum --- charts/parity/Chart.yaml | 2 +- charts/parity/templates/statefulset.yaml | 2 +- charts/parity/values.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/parity/Chart.yaml b/charts/parity/Chart.yaml index 8b79415..bbaed3f 100644 --- a/charts/parity/Chart.yaml +++ b/charts/parity/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v1 appVersion: "2.7" description: Parity chart for Kubernetes name: parity -version: 0.1.49 +version: 0.1.50 diff --git a/charts/parity/templates/statefulset.yaml b/charts/parity/templates/statefulset.yaml index 22e82a2..31bc3b0 100644 --- a/charts/parity/templates/statefulset.yaml +++ b/charts/parity/templates/statefulset.yaml @@ -73,7 +73,7 @@ spec: livenessProbe: exec: command: - - /bin/bash + - /bin/sh - /scripts/check_node_health.sh - http://127.0.0.1:{{ .Values.service.rpcPort }} - "300" diff --git a/charts/parity/values.yaml b/charts/parity/values.yaml index b9cf40b..9cb714b 100644 --- a/charts/parity/values.yaml +++ b/charts/parity/values.yaml @@ -8,7 +8,7 @@ terminationGracePeriodSeconds: 180 image: repository: parity/parity - tag: v2.5.13-stable + tag: v2.7.2-stable pullPolicy: IfNotPresent imagePullSecrets: [] From 1584df77476e8800b8095a7db684c7647d182ed3 Mon Sep 17 00:00:00 2001 From: Alex Vorona Date: Wed, 1 Jul 2020 18:24:05 +0300 Subject: [PATCH 2/5] [tezos] switch from LB to nodePort, as tezos node cannot specify announced external IP --- charts/tezos/Chart.yaml | 2 +- charts/tezos/templates/lb-p2p.yaml | 7 ++++--- charts/tezos/values.yaml | 4 +++- resources.md | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/charts/tezos/Chart.yaml b/charts/tezos/Chart.yaml index 74b7d18..1c0af8d 100755 --- a/charts/tezos/Chart.yaml +++ b/charts/tezos/Chart.yaml @@ -14,4 +14,4 @@ name: tezos sources: - https://github.com/kubernetes/charts - https://gitlab.com/tezos/tezos -version: 0.1.0 +version: 0.1.1 diff --git a/charts/tezos/templates/lb-p2p.yaml b/charts/tezos/templates/lb-p2p.yaml index 764de8e..c9dd83a 100644 --- a/charts/tezos/templates/lb-p2p.yaml +++ b/charts/tezos/templates/lb-p2p.yaml @@ -8,13 +8,14 @@ metadata: chain: {{ .Values.tezos.chain_id }} {{ include "tezos.labels" . | indent 4 }} spec: - type: LoadBalancer - {{ if .Values.configurationFile.externalLBp2pIP -}} - loadBalancerIP: {{ .Values.configurationFile.externalLBp2pIP }} + type: NodePort + {{ if .Values.externalLBp2pIP -}} + loadBalancerIP: {{ .Values.externalLBp2pIP }} {{ end -}} ports: - name: {{ .Values.service.p2pPortName }} port: {{ .Values.service.p2pPort }} + nodePort: {{ .Values.service.p2pPort }} targetPort: {{ .Values.service.p2pPortName }} selector: app.kubernetes.io/name: {{ include "tezos.name" . }} diff --git a/charts/tezos/values.yaml b/charts/tezos/values.yaml index 42e65ec..96dbfe4 100755 --- a/charts/tezos/values.yaml +++ b/charts/tezos/values.yaml @@ -10,7 +10,8 @@ image: service: rpcPortName: jsonrpc rpcPort: "8732" - p2pPort: "9732" + # port should be inside k8s node ports range + p2pPort: "30000" p2pPortName: p2p externalLB: false @@ -20,6 +21,7 @@ externalLBSourceRanges: {} # - 203.0.113.3/32 externalLBp2p: false +externalLBp2pIP: "" internalLB: false internalLBIP: "" diff --git a/resources.md b/resources.md index 29e9417..b9a4f6d 100644 --- a/resources.md +++ b/resources.md @@ -15,7 +15,7 @@ Parity version 2.5/2.6 loves memory. And it absolutely loves low disk latency, w Simple IOPS increase may not help, as disk access is more or less single-threaded during sync and thus may be limited by IO latency instead of IOPS. Local NVMe disk will do it's job for chains like ETC, but it's size is not enough to work with ETH mainnet usually. Here is some hack to speedup initial sync - get instance with tons of RAM and preload synced blockchain into OS cache. -My case was 640GB of RAM and blockchain preload from inside container via `find | xargs cat > /dev/null` or [vmtouch](https://github.com/hoytech/vmtouch/), +My case was 640GB of RAM and blockchain preload from inside container via `find -type f| xargs cat > /dev/null` or [vmtouch](https://github.com/hoytech/vmtouch/), 3-5x speedup from 0.5-2 blocks/sec(100-200 tx/sec) to 7-10 blocks/sec (700-1000 tx/sec) and sustained blockchain write near 150MB/s, just $1/hour with preemptible nodes. Get pre-synced snapshot when you can :) @@ -76,3 +76,17 @@ TBD | Chain | CPU req/lim | Memory req/lim | Disk size | Disk IOPS | Disk latency| |-------|-------------|----------------|-----------|-----------|-------------| |mainnet|0|0|0|0|-| + +## Thezos +You may use [pre-synced snapshot](https://tezos.stackexchange.com/questions/1385/available-snapshots-for-main-net) to bootstrap Your node. But here are resources requirements to sync from scratch. +### Initial sync +| Chain | CPU req/lim | Memory req/lim | Disk size | Disk IOPS | Disk latency| +|-------|-------------|----------------|-----------|-----------|-------------| +|mainnet|1.5/2.2|4G/6G|50GB SSD|1200+|low| + +### Keep chain synced +TBD + +| Chain | CPU req/lim | Memory req/lim | Disk size | Disk IOPS | Disk latency| +|-------|-------------|----------------|-----------|-----------|-------------| +|mainnet|0.1/1|2G/3G|50GB HDD|30+|medium| From f98dc922a5046ff71d4fb06a23a8430cbb075720 Mon Sep 17 00:00:00 2001 From: Alex Vorona Date: Wed, 30 Sep 2020 12:15:55 +0300 Subject: [PATCH 3/5] [bsc] add binance smart chain --- charts/bsc/.helmignore | 24 ++++ charts/bsc/Chart.yaml | 5 + charts/bsc/templates/NOTES.txt | 12 ++ charts/bsc/templates/_check_node_health.sh | 34 +++++ charts/bsc/templates/_config.toml | 91 +++++++++++++ charts/bsc/templates/_helpers.tpl | 45 +++++++ charts/bsc/templates/configmap.yaml | 16 +++ charts/bsc/templates/ilb.yaml | 32 +++++ charts/bsc/templates/ingress.yaml | 36 +++++ charts/bsc/templates/lb-p2p-discovery.yaml | 23 ++++ charts/bsc/templates/lb-p2p.yaml | 23 ++++ charts/bsc/templates/lb.yaml | 35 +++++ charts/bsc/templates/service.yaml | 14 ++ charts/bsc/templates/statefulset.yaml | 150 +++++++++++++++++++++ charts/bsc/values.yaml | 141 +++++++++++++++++++ 15 files changed, 681 insertions(+) create mode 100644 charts/bsc/.helmignore create mode 100644 charts/bsc/Chart.yaml create mode 100644 charts/bsc/templates/NOTES.txt create mode 100644 charts/bsc/templates/_check_node_health.sh create mode 100644 charts/bsc/templates/_config.toml create mode 100644 charts/bsc/templates/_helpers.tpl create mode 100644 charts/bsc/templates/configmap.yaml create mode 100644 charts/bsc/templates/ilb.yaml create mode 100644 charts/bsc/templates/ingress.yaml create mode 100644 charts/bsc/templates/lb-p2p-discovery.yaml create mode 100644 charts/bsc/templates/lb-p2p.yaml create mode 100644 charts/bsc/templates/lb.yaml create mode 100644 charts/bsc/templates/service.yaml create mode 100644 charts/bsc/templates/statefulset.yaml create mode 100644 charts/bsc/values.yaml diff --git a/charts/bsc/.helmignore b/charts/bsc/.helmignore new file mode 100644 index 0000000..7c21662 --- /dev/null +++ b/charts/bsc/.helmignore @@ -0,0 +1,24 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ +cloudbuild.yaml + diff --git a/charts/bsc/Chart.yaml b/charts/bsc/Chart.yaml new file mode 100644 index 0000000..d45a97f --- /dev/null +++ b/charts/bsc/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0.0" +description: Binance Smart Chain chart for Kubernetes +name: bsc +version: 0.1.0 diff --git a/charts/bsc/templates/NOTES.txt b/charts/bsc/templates/NOTES.txt new file mode 100644 index 0000000..d51da62 --- /dev/null +++ b/charts/bsc/templates/NOTES.txt @@ -0,0 +1,12 @@ +bsc RPC can be accessed via port {{ .Values.service.rpcPort }} on the following DNS name from within your cluster: +{{ .Release.Name }}-service.{{ .Release.Namespace }}.svc.cluster.local + +To connect to bsc RPC: + +1. Forward the port for the node: + + $ kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bsc.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{ .items[0].metadata.name }") {{ .Values.service.rpcPort }} + +2. Test connection : + + $ curl -k http://127.0.0.1:{{ .Values.service.rpcPort }} --data-binary '{"method":"bsc_versionInfo","params":[],"id":1,"jsonrpc":"2.0"}' -H 'Content-Type: application/json' diff --git a/charts/bsc/templates/_check_node_health.sh b/charts/bsc/templates/_check_node_health.sh new file mode 100644 index 0000000..2303b3a --- /dev/null +++ b/charts/bsc/templates/_check_node_health.sh @@ -0,0 +1,34 @@ +set -ex # -e exits on error + +usage() { echo "Usage: $0 ]" 1>&2; exit 1; } + +rpc_endpoint="$1" +max_lag_in_seconds="$2" +last_synced_block_file="$3" + +if [ -z "${rpc_endpoint}" ] || [ -z "${max_lag_in_seconds}" ] || [ -z "${last_synced_block_file}" ]; then + usage +fi + +block_number=$(geth --datadir={{ .Values.bsc.base_path }} attach --exec "eth.blockNumber") + +if [ -z "${block_number}" ] || [ "${block_number}" == "null" ]; then + echo "Block number returned by the node is empty or null" + exit 1 +fi + +if [ ! -f ${last_synced_block_file} ]; then + old_block_number=""; +else + old_block_number=$(cat ${last_synced_block_file}); +fi; + +if [ "${block_number}" != "${old_block_number}" ]; then + mkdir -p $(dirname "${last_synced_block_file}") + echo ${block_number} > ${last_synced_block_file} +fi + +file_age=$(($(date +%s) - $(date -r ${last_synced_block_file} +%s))); +max_age=${max_lag_in_seconds}; +echo "${last_synced_block_file} age is $file_age seconds. Max healthy age is $max_age seconds"; +if [ ${file_age} -lt ${max_age} ]; then exit 0; else exit 1; fi diff --git a/charts/bsc/templates/_config.toml b/charts/bsc/templates/_config.toml new file mode 100644 index 0000000..7424c38 --- /dev/null +++ b/charts/bsc/templates/_config.toml @@ -0,0 +1,91 @@ +[Eth] +NetworkId = 96 +SyncMode = "full" +DiscoveryURLs = [] +NoPruning = false +NoPrefetch = false +LightPeers = 100 +UltraLightFraction = 75 +DatabaseCache = 512 +DatabaseFreezer = "" +TrieCleanCache = 256 +TrieDirtyCache = 256 +TrieTimeout = 3600000000000 +EnablePreimageRecording = false +EWASMInterpreter = "" +EVMInterpreter = "" + +[Eth.Miner] +GasFloor = 30000000 +GasCeil = 40000000 +GasPrice = 18000000000 +Recommit = 10000000000 +Noverify = false + +[Eth.Ethash] +CacheDir = "" +CachesInMem = 0 +CachesOnDisk = 0 +CachesLockMmap = false +DatasetDir = "" +DatasetsInMem = 0 +DatasetsOnDisk = 0 +DatasetsLockMmap = false +PowMode = 0 + +[Eth.TxPool] +Locals = [] +NoLocals = true +Journal = "transactions.rlp" +Rejournal = 3600000000000 +PriceLimit = 18000000000 +PriceBump = 10 +AccountSlots = 16 +GlobalSlots = 4096 +AccountQueue = 64 +GlobalQueue = 1024 +Lifetime = 10800000000000 + +[Eth.GPO] +Blocks = 20 +Percentile = 60 + +[Shh] +MaxMessageSize = 1048576 +RestrictConnectionBetweenLightClients = true + +[Node] +DataDir = "node" +omitempty = "" +InsecureUnlockAllowed = false +NoUSB = true +IPCPath = "geth.ipc" +# it overrides cli arg +#HTTPHost = "0.0.0.0" +HTTPPort = 8575 +HTTPVirtualHosts = ["*"] +HTTPModules = ["eth", "net", "web3", "txpool", "parlia"] +WSPort = 8576 +WSModules = ["net", "web3", "eth"] +GraphQLPort = 8577 +GraphQLVirtualHosts = ["*"] + +[Node.P2P] +MaxPeers = 50 +NoDiscovery = false +BootstrapNodes = ["enode://29647b99b82a88c6c975bfd003eba61af5f5c19a0c6aafb4a9fc58555a30481e73a613b46e55c6ad717ad94a4ccfe1d1dd63cf2943b82565b45f7dcbe5aa77a0@52.199.214.252:30311","enode://2ac0d0479a91adb6227d914e2d5fb327465d1500c2d08488ff53c31be537c4b1b4f87634745c25a30cceaba44485463d4bae22ccf276de4b722b413a2296c91e@18.181.52.189:30311","enode://689641bba38fcf8d2f1aa33a82ea4f3a8f678b3cbbd1bfedd21f0df20b86ea64d90085084239e6ffdfe68e441726ca674a9af26deb66d40eb9456ca692b2f17c@52.51.80.128:30311","enode://a83769032be75aa38a53771234140432e4ca54986d1cee75c92ad760ab67668b43b0f60d9e86fe646c3a1a53543c6721b627877deda3bb1c2f12b779d2487ccc@34.242.33.165:30311","enode://3cbb7c7dd6d0c9400b3cbfd70876c27e08df352f0b5c32ee396eb68ce44ccc43eed004b91f5862458598fa7a123bb913f5e0b77eca93f9314565fa26e5c384db@3.209.122.123:30311","enode://13c9d1bee5bcef2401023a4fa2028497e1063f1137800322ce3d5c5c5d2f004e1157600767567f0e504b1e8ef29e589831e8916b9a3c3f9c798f3e6c076915e6@52.72.123.113:30311"] +StaticNodes = [] +TrustedNodes = ["enode://29647b99b82a88c6c975bfd003eba61af5f5c19a0c6aafb4a9fc58555a30481e73a613b46e55c6ad717ad94a4ccfe1d1dd63cf2943b82565b45f7dcbe5aa77a0@52.199.214.252:30311","enode://2ac0d0479a91adb6227d914e2d5fb327465d1500c2d08488ff53c31be537c4b1b4f87634745c25a30cceaba44485463d4bae22ccf276de4b722b413a2296c91e@18.181.52.189:30311","enode://689641bba38fcf8d2f1aa33a82ea4f3a8f678b3cbbd1bfedd21f0df20b86ea64d90085084239e6ffdfe68e441726ca674a9af26deb66d40eb9456ca692b2f17c@52.51.80.128:30311","enode://a83769032be75aa38a53771234140432e4ca54986d1cee75c92ad760ab67668b43b0f60d9e86fe646c3a1a53543c6721b627877deda3bb1c2f12b779d2487ccc@34.242.33.165:30311","enode://3cbb7c7dd6d0c9400b3cbfd70876c27e08df352f0b5c32ee396eb68ce44ccc43eed004b91f5862458598fa7a123bb913f5e0b77eca93f9314565fa26e5c384db@3.209.122.123:30311","enode://13c9d1bee5bcef2401023a4fa2028497e1063f1137800322ce3d5c5c5d2f004e1157600767567f0e504b1e8ef29e589831e8916b9a3c3f9c798f3e6c076915e6@52.72.123.113:30311"] +ListenAddr = ":30311" +EnableMsgEvents = false + +[Node.HTTPTimeouts] +ReadTimeout = 30000000000 +WriteTimeout = 30000000000 +IdleTimeout = 120000000000 + +[Node.LogConfig] +FileRoot = "" +FilePath = "bsc.log" +MaxBytesSize = 10485760 +Level = "info" diff --git a/charts/bsc/templates/_helpers.tpl b/charts/bsc/templates/_helpers.tpl new file mode 100644 index 0000000..ca88e15 --- /dev/null +++ b/charts/bsc/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "bsc.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "bsc.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "bsc.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "bsc.labels" -}} +app.kubernetes.io/name: {{ include "bsc.name" . }} +helm.sh/chart: {{ include "bsc.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/charts/bsc/templates/configmap.yaml b/charts/bsc/templates/configmap.yaml new file mode 100644 index 0000000..b724b19 --- /dev/null +++ b/charts/bsc/templates/configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "{{ .Release.Name }}-config" +data: + config.toml: |- + {{- include (print $.Template.BasePath "/_config.toml") . | nindent 4 }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: "{{ .Release.Name }}-scripts" +data: + check_node_health.sh: |- + {{- include (print $.Template.BasePath "/_check_node_health.sh") . | nindent 4 }} +--- diff --git a/charts/bsc/templates/ilb.yaml b/charts/bsc/templates/ilb.yaml new file mode 100644 index 0000000..3d6a4e2 --- /dev/null +++ b/charts/bsc/templates/ilb.yaml @@ -0,0 +1,32 @@ +{{ if .Values.internalLB }} +## use this to aggregate internal pods behind +## a single load balanced IP +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-ilb + labels: + chain: eth +{{ include "bsc.labels" . | indent 4 }} + annotations: + cloud.google.com/load-balancer-type: "Internal" + cloud.google.com/network-tier: "PREMIUM" +spec: + type: LoadBalancer + {{ if .Values.internalLBIP }} + loadBalancerIP: {{ .Values.internalLBIP }} + {{ end }} + ports: + - name: {{ .Values.service.rpcPortName }} + port: {{ .Values.service.rpcPort }} + targetPort: {{ .Values.service.rpcPortName }} + - name: {{ .Values.service.wsPortName }} + port: {{ .Values.service.wsPort }} + targetPort: {{ .Values.service.wsPortName }} + - name: {{ .Values.service.graphQlPortName }} + port: {{ .Values.service.graphQlPort }} + targetPort: {{ .Values.service.graphQlPortName }} + selector: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/bsc/templates/ingress.yaml b/charts/bsc/templates/ingress.yaml new file mode 100644 index 0000000..cce1b1f --- /dev/null +++ b/charts/bsc/templates/ingress.yaml @@ -0,0 +1,36 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "bsc.fullname" . -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: +{{ include "bsc.labels" . | indent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/bsc/templates/lb-p2p-discovery.yaml b/charts/bsc/templates/lb-p2p-discovery.yaml new file mode 100644 index 0000000..b3f32a9 --- /dev/null +++ b/charts/bsc/templates/lb-p2p-discovery.yaml @@ -0,0 +1,23 @@ +{{ if .Values.externalLBp2pDiscovery }} +## use this if you want to expose blockchain p2p (not RPC) to public +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-lb-p2p-discovery + labels: + chain: eth +{{ include "bsc.labels" . | indent 4 }} +spec: + type: LoadBalancer + {{ if .Values.externalLBp2pDiscoveryIP }} + loadBalancerIP: {{ .Values.externalLBp2pDiscoveryIP }} + {{ end }} + ports: + - name: {{ .Values.service.p2pPortName1 }} + port: {{ .Values.service.p2pPort1 }} + targetPort: {{ .Values.service.p2pPortName1 }} + protocol: {{ .Values.service.p2pPortProtocol1 }} + selector: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/bsc/templates/lb-p2p.yaml b/charts/bsc/templates/lb-p2p.yaml new file mode 100644 index 0000000..f527d81 --- /dev/null +++ b/charts/bsc/templates/lb-p2p.yaml @@ -0,0 +1,23 @@ +{{ if .Values.externalLBp2p }} +## use this if you want to expose blockchain p2p (not RPC) to public +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-lb-p2p + labels: + chain: eth +{{ include "bsc.labels" . | indent 4 }} +spec: + type: LoadBalancer + {{ if .Values.externalLBp2pIP }} + loadBalancerIP: {{ .Values.externalLBp2pIP }} + {{ end }} + ports: + - name: {{ .Values.service.p2pPortName0 }} + port: {{ .Values.service.p2pPort0 }} + targetPort: {{ .Values.service.p2pPortName0 }} + protocol: {{ .Values.service.p2pPortProtocol0 }} + selector: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/bsc/templates/lb.yaml b/charts/bsc/templates/lb.yaml new file mode 100644 index 0000000..734e70b --- /dev/null +++ b/charts/bsc/templates/lb.yaml @@ -0,0 +1,35 @@ +{{ if .Values.externalLB }} +## only use this if you want to expose +## json services to a public ip +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-lb + labels: + chain: eth +{{ include "bsc.labels" . | indent 4 }} +spec: + type: LoadBalancer + {{ if .Values.externalLBIP }} + loadBalancerIP: {{ .Values.externalLBIP }} + {{ end }} + {{- if .Values.externalLBSourceRanges }} + loadBalancerSourceRanges: + {{- range $val := .Values.externalLBSourceRanges }} + - {{ $val -}} + {{ end }} + {{ end }} + ports: + - name: {{ .Values.service.rpcPortName }} + port: {{ .Values.service.rpcPort }} + targetPort: {{ .Values.service.rpcPortName }} + - name: {{ .Values.service.wsPortName }} + port: {{ .Values.service.wsPort }} + targetPort: {{ .Values.service.wsPortName }} + - name: {{ .Values.service.graphQlPortName }} + port: {{ .Values.service.graphQlPort }} + targetPort: {{ .Values.service.graphQlPortName }} + selector: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/bsc/templates/service.yaml b/charts/bsc/templates/service.yaml new file mode 100644 index 0000000..dc040d2 --- /dev/null +++ b/charts/bsc/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-service + labels: + chain: eth +{{ include "bsc.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + {{- toYaml .Values.service.ports | nindent 4 }} + selector: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/bsc/templates/statefulset.yaml b/charts/bsc/templates/statefulset.yaml new file mode 100644 index 0000000..81eb526 --- /dev/null +++ b/charts/bsc/templates/statefulset.yaml @@ -0,0 +1,150 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "bsc.fullname" . }} + labels: +{{ include "bsc.labels" . | indent 4 }} +spec: + serviceName: "{{ .Release.Name }}-service" + replicas: {{ .Values.replicaCount }} # by default is 1 + selector: + matchLabels: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + bsc/chain: {{ .Values.bsc.chain }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "bsc.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + bsc/chain: {{ .Values.bsc.chain }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + spec: + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.bscCmdOverride }} + command: [ "{{ .Values.bscCmd }}" ] + {{- end }} + args: + - --config=/config/config.toml + - --datadir={{ .Values.bsc.base_path }} + - --syncmode={{ .Values.bsc.syncmode }} + - --gcmode={{ .Values.bsc.gcmode }} + - --rpc + - --rpcaddr=0.0.0.0 + - --rpcport={{ .Values.service.rpcPort }} + - --rpcapi="{{ .Values.bsc.rpcApi }}" + - --rpcvhosts="{{ .Values.bsc.rpcVhosts }}" + - --ws + - --wsaddr=0.0.0.0 + - --wsport={{ .Values.service.wsPort }} + - --wsapi="{{ .Values.bsc.wsApi }}" + - --wsorigins="{{ .Values.bsc.wsOrigins }}" + - --graphql + - --graphql.addr=0.0.0.0 + - --graphql.port={{ .Values.service.graphQlPort }} + - --graphql.vhosts="{{ .Values.bsc.graphQlVhosts }}" + - --maxpeers={{ .Values.bsc.maxpeers }} + - --cache={{ .Values.bsc.cache }} + - --port={{ .Values.service.p2pPort0 }} + {{- if and .Values.externalLBp2p .Values.externalLBp2pIP }} + - --nat=extip:{{- .Values.externalLBp2pIP -}} + {{- end }} + workingDir: "{{ .Values.bsc.base_path }}" + resources: + {{- toYaml .Values.resources | nindent 10 }} + ports: + {{- range $val := .Values.service.ports }} + - containerPort: {{ $val.port }} + name: "{{ $val.name }}" + protocol: {{ $val.protocol | default "TCP" }} + {{- end }} + volumeMounts: + - name: bsc-config + mountPath: /config + - name: scripts + mountPath: /scripts + - name: bsc-pvc + mountPath: {{ .Values.bsc.base_path }} + livenessProbe: + exec: + command: + - /bin/sh + - /scripts/check_node_health.sh + - http://127.0.0.1:{{ .Values.service.rpcPort }} + - "300" + - last_synced_block.txt + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.livenessProbe.failureThreshold }} + - name: logger + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: [ "tail","-F","{{ .Values.bsc.base_path }}/bsc.log" ] + workingDir: "{{ .Values.bsc.base_path }}" + volumeMounts: + - name: bsc-pvc + mountPath: {{ .Values.bsc.base_path }} + readOnly: true + initContainers: + {{- if .Values.init_genesis }} + - name: init + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["/bin/sh", "-c", "wget -O /tmp/genesis.json + https://github.com/binance-chain/smart-chain-binary/raw/master/bsc/fullnode/config/genesis.json && + geth --datadir={{ .Values.bsc.base_path }} init /tmp/genesis.json"] + volumeMounts: + - name: bsc-pvc + mountPath: {{ .Values.bsc.base_path }} + {{- end }} + volumes: + - name: bsc-config + configMap: + name: "{{ .Release.Name }}-config" + - name: scripts + configMap: + name: "{{ .Release.Name }}-scripts" + volumeClaimTemplates: + - metadata: + name: bsc-pvc + spec: + accessModes: + - {{.Values.persistence.accessMode }} + {{- if .Values.persistence.storageClass }} + {{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" + {{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" + {{- end }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size }} + volumeMode: Filesystem diff --git a/charts/bsc/values.yaml b/charts/bsc/values.yaml new file mode 100644 index 0000000..3adc97b --- /dev/null +++ b/charts/bsc/values.yaml @@ -0,0 +1,141 @@ +# Default values for bsc. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +terminationGracePeriodSeconds: 180 + +image: + repository: dysnix/bsc + tag: latest + pullPolicy: Always + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +# enable this only once - when your blockchain is empty. It overwrites everything +init_genesis: false + +# Don't use spaces or special chars +bsc: + # we don't have other chains, it's just a pod label for now + chain: testnet + # Blockchain sync mode ("fast", "full", or "light") (default: fast) + syncmode: "full" + # Blockchain garbage collection mode ("full", "archive") (default: "full") + gcmode: "archive" + base_path: "/data" + rpcApi: "eth,net,web3,txpool,parlia" + rpcVhosts: "*" + wsApi: "net,web3,eth" + wsOrigins: "*" + graphQlVhosts: "*" + maxpeers: 50 + cache: 4096 + +livenessProbe: + initialDelaySeconds: 300 + periodSeconds: 300 + timeoutSeconds: 10 + successThreshold: 1 + failureThreshold: 2 + +service: + type: ClusterIP + rpcPortName: &rpcPortName jsonrpc + rpcPort: &rpcPort 8575 + wsPort: &wsPort 8576 + wsPortName: &wsPortName web-socket + graphQlPort: &graphQlPort 8577 + graphQlPortName: &graphQlPortName qraphql + p2pPort0: &p2pPort0 30311 + p2pPortName0: &p2pPortName0 p2p + p2pPortProtocol0: &p2pPortProtocol0 TCP + p2pPort1: &p2pPort1 30311 + p2pPortName1: &p2pPortName1 p2p-discovery + p2pPortProtocol1: &p2pPortProtocol1 UDP + ports: + - port: *rpcPort + name: *rpcPortName + - port: *wsPort + name: *wsPortName + - port: *graphQlPort + name: *graphQlPortName + - port: *p2pPort0 + name: *p2pPortName0 + protocol: *p2pPortProtocol0 + - port: *p2pPort1 + name: *p2pPortName1 + protocol: *p2pPortProtocol1 + +bscCmdOverride: false +bscCmd: "" + +externalLB: false +externalLBIP: "" +externalLBSourceRanges: {} +# - 198.51.100.1/32 +# - 198.51.100.2/32 + +externalLBp2p: false +externalLBp2pIP: 203.0.113.0 + +externalLBp2pDiscovery: false +externalLBp2pDiscoveryIP: 203.0.113.0 + +internalLB: false +internalLBIP: "" + +persistence: + enabled: true +# storageClass: "standard" + accessMode: ReadWriteOnce + size: "10Gi" + + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: + requests: + cpu: "1000m" + memory: "2000Mi" + limits: + cpu: "3000m" + memory: "5000Mi" + +securityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + + +nodeSelector: {} + +tolerations: [] + +affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchLabels: + app.kubernetes.io/name: "bsc" + bsc/chain: "testnet" + topologyKey: failure-domain.beta.kubernetes.io/zone + + From dd3e2baadd1b9de6b6aff3b6a5588b04ab3e829a Mon Sep 17 00:00:00 2001 From: Alex Vorona Date: Wed, 30 Sep 2020 12:16:11 +0300 Subject: [PATCH 4/5] [bc] add binance chain --- charts/binancechain/.helmignore | 22 ++++ charts/binancechain/Chart.yaml | 17 +++ charts/binancechain/README.md | 63 +++++++++ charts/binancechain/templates/NOTES.txt | 14 ++ charts/binancechain/templates/_app.toml | 113 ++++++++++++++++ .../templates/_check_node_health.sh | 39 ++++++ charts/binancechain/templates/_helpers.tpl | 45 +++++++ charts/binancechain/templates/configmap.yaml | 7 + charts/binancechain/templates/ilb.yaml | 29 +++++ charts/binancechain/templates/lb-p2p.yaml | 22 ++++ charts/binancechain/templates/lb.yaml | 32 +++++ charts/binancechain/templates/secret.yaml | 23 ++++ charts/binancechain/templates/service.yaml | 18 +++ .../binancechain/templates/statefulset.yaml | 123 ++++++++++++++++++ charts/binancechain/values.yaml | 83 ++++++++++++ 15 files changed, 650 insertions(+) create mode 100755 charts/binancechain/.helmignore create mode 100755 charts/binancechain/Chart.yaml create mode 100755 charts/binancechain/README.md create mode 100644 charts/binancechain/templates/NOTES.txt create mode 100644 charts/binancechain/templates/_app.toml create mode 100755 charts/binancechain/templates/_check_node_health.sh create mode 100644 charts/binancechain/templates/_helpers.tpl create mode 100644 charts/binancechain/templates/configmap.yaml create mode 100644 charts/binancechain/templates/ilb.yaml create mode 100644 charts/binancechain/templates/lb-p2p.yaml create mode 100644 charts/binancechain/templates/lb.yaml create mode 100644 charts/binancechain/templates/secret.yaml create mode 100644 charts/binancechain/templates/service.yaml create mode 100644 charts/binancechain/templates/statefulset.yaml create mode 100755 charts/binancechain/values.yaml diff --git a/charts/binancechain/.helmignore b/charts/binancechain/.helmignore new file mode 100755 index 0000000..f750b3a --- /dev/null +++ b/charts/binancechain/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +cloudbuild.yaml diff --git a/charts/binancechain/Chart.yaml b/charts/binancechain/Chart.yaml new file mode 100755 index 0000000..707be96 --- /dev/null +++ b/charts/binancechain/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +appVersion: 1.0.0 +description: binancechain is building the Internet of Trusted Things, an open network where all physical and virtual “things” — + humans, machines, and businesses — can interact with full trust and privacy. +engine: gotpl +home: https://binancechain.io +keywords: +- binancechain +- cryptocurrency +maintainers: +- email: av@dysnix.com + name: voron +name: binancechain +sources: +- https://github.com/kubernetes/charts +- https://github.com/binancechainproject/binancechain-core/ +version: 0.1.0 diff --git a/charts/binancechain/README.md b/charts/binancechain/README.md new file mode 100755 index 0000000..34dd20d --- /dev/null +++ b/charts/binancechain/README.md @@ -0,0 +1,63 @@ +# binancechain + +[binancechain](https://binancechain.com) is a distributed consensus platform with meta-consensus capability. binancechain not only comes to consensus about the state of its ledger, like Bitcoin or Ethereum. +It also attempts to come to consensus about how the protocol and the nodes should adapt and upgrade. +## Introduction + +This chart bootstraps a single binancechain node deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. +Docker image was taken from [binancechain on Docker hub](https://hub.docker.com/r/binancechain/binancechain/tags) + +## Prerequisites + +- Kubernetes 1.8+ +- PV provisioner support in the underlying infrastructure + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```bash +$ helm install --name my-release stable/binancechain +``` + +The command deploys binancechain on the Kubernetes cluster in the default configuration. +The [configuration](#configuration) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```bash +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following table lists the configurable parameters of the binancechain chart and their default values. + +Parameter | Description | Default +------------------------------- | ------------------------------------------------- | ---------------------------------------------------------- +`image.repository` | Image source repository name | `arilot/docker-binancechain` +`image.tag` | `binancechain` release tag. | `0.17.1` +`image.pullPolicy` | Image pull policy | `IfNotPresent` +`service.rpcPort` | RPC port | `8732` +`service.p2pPort` | P2P port | `9732` +`persistence.enabled` | Create a volume to store data | `true` +`persistence.accessMode` | ReadWriteOnce or ReadOnly | `ReadWriteOnce` +`persistence.size` | Size of persistent volume claim | `300Gi` +`resources` | CPU/Memory resource requests/limits | `{}` +`terminationGracePeriodSeconds` | Wait time before forcefully terminating container | `30` + + +Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example, + +```bash +$ helm install --name my-release -f values.yaml stable/binancechain +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) + diff --git a/charts/binancechain/templates/NOTES.txt b/charts/binancechain/templates/NOTES.txt new file mode 100644 index 0000000..9d649a2 --- /dev/null +++ b/charts/binancechain/templates/NOTES.txt @@ -0,0 +1,14 @@ +binancechain RPC can be accessed via port {{ .Values.service.rpcPort }} on the following DNS name from within your cluster: +{{ template "binancechain.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local + +To connect to binancechain RPC: + +1. Forward the port for the node: + + $ kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "binancechain.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{ .items[0].metadata.name }") {{ .Values.service.rpcPort }} + +2. Test connection: + + $ curl http://127.0.0.1:{{ .Values.service.rpcPort }}/monitor/heads/{{ .Values.binancechain.chain_id }} + +3. See https://codelabs.binancechain.io for details diff --git a/charts/binancechain/templates/_app.toml b/charts/binancechain/templates/_app.toml new file mode 100644 index 0000000..03f7853 --- /dev/null +++ b/charts/binancechain/templates/_app.toml @@ -0,0 +1,113 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +[base] +# Interval blocks of breathe block, if breatheBlockInterval is 0, breathe block will be created every day. +breatheBlockInterval = 0 +# Size of account cache +accountCacheSize = 30000 +# Size of signature cache +signatureCacheSize = 30000 +# Running mode when start up, 0: Normal, 1: TransferOnly, 2: RecoverOnly +startMode = 0 +# Concurrency of OrderKeeper, should be power of 2 +orderKeeperConcurrency = 2 +# Days count back for breathe block +breatheBlockDaysCountBack = 7 + +[upgrade] +# Block height of BEP6 upgrade +BEP6Height = 20300000 +# Block height of BEP9 upgrade +BEP9Height = 20300000 +# Block height of BEP10 upgrade +BEP10Height = 20300000 +# Block height of BEP19 upgrade +BEP19Height = 20300000 +# Block height of BEP12 upgrade +BEP12Height = 25120000 +# Block height of BEP3 upgrade +BEP3Height = 41277000 +# Block height of FixSignBytesOverflow upgrade +FixSignBytesOverflowHeight = 51467800 +# Block height of LotSizeOptimization upgrade +LotSizeUpgradeHeight = 51467800 +# Block height of changing listing rule upgrade +ListingRuleUpgradeHeight = 51467800 +# Block height of FixZeroBalanceHeight upgrade +FixZeroBalanceHeight = 51467800 +# Block height of BEP8 upgrade +BEP8Height = 99550000 +# Block height of BEP67 upgrade +BEP67Height = 99550000 +# Block height of BEP70 upgrade +BEP70Height = 99550000 + +[addr] +# Bech32PrefixAccAddr defines the Bech32 prefix of an account's address +bech32PrefixAccAddr = "bnb" +# Bech32PrefixAccPub defines the Bech32 prefix of an account's public key +bech32PrefixAccPub = "bnbp" +# Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address +bech32PrefixValAddr = "bva" +# Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key +bech32PrefixValPub = "bvap" +# Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address +bech32PrefixConsAddr = "bca" +# Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key +bech32PrefixConsPub = "bcap" + +##### publication related configurations ##### +[publication] +# configurations ends with Kafka can be a semi-colon separated host-port list +# Whether we want publish market data (this includes trades and order) +publishOrderUpdates = true +orderUpdatesTopic = "orders" +orderUpdatesKafka = "127.0.0.1:9092" + +# Whether we want publish account balance to notify browser db indexer persist latest account balance change +publishAccountBalance = true +accountBalanceTopic = "accounts" +accountBalanceKafka = "127.0.0.1:9092" + +# Whether we want publish order book changes +publishOrderBook = true +orderBookTopic = "orders" +orderBookKafka = "127.0.0.1:9092" + +# Whether we want publish block fee changes +publishBlockFee = true +blockFeeTopic = "accounts" +blockFeeKafka = "127.0.0.1:9092" + +# Whether we want publish transfers +publishTransfer = true +transferTopic = "transfers" +transferKafka = "127.0.0.1:9092" + +# Global setting +publicationChannelSize = "10000" +publishKafka = false +publishLocal = true +# max size in megabytes of marketdata json file before rotate +localMaxSize = 1024 +# max days of marketdata json files to keep before deleted +localMaxAge = 1000 + +[log] + +# Write logs to console instead of file +logToConsole = true + +## The below parameters take effect only when logToConsole is false +# Log file root, if not set, use home path +logFileRoot = "" +# Log file path relative to log file root path +logFilePath = "bnc.log" +# Number of logs keep in memory before writing to file +logBuffSize = 10000 + + +[dex] +# The suffixed symbol of BUSD +BUSDSymbol = "BUSD-BD1" diff --git a/charts/binancechain/templates/_check_node_health.sh b/charts/binancechain/templates/_check_node_health.sh new file mode 100755 index 0000000..d6058d0 --- /dev/null +++ b/charts/binancechain/templates/_check_node_health.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env sh +set -ex # -e exits on error + +usage() { echo "Usage: $0 ]" 1>&2; exit 1; } + +datadir="$1" +max_lag_in_seconds="$2" +last_synced_block_file="$3" + +if [ -z "${datadir}" ] || [ -z "${max_lag_in_seconds}" ] || [ -z "${last_synced_block_file}" ]; then + usage +fi + +set +e + +block_timestamp=$(binancechain-client --chain {{ .Values.binancechain.chain_id }} --block head get timestamp -s) + +set -e +# https://unix.stackexchange.com/a/367406/255685 +if [ -z "${block_timestamp}" ] || [ ${block_timestamp} -le 0 ]; then + echo "Block number returned by the node is empty or not a number" + exit 1 +fi + +if [ ! -f ${last_synced_block_file} ]; then + old_block_timestamp=""; +else + old_block_timestamp=$(cat ${last_synced_block_file}); +fi; + +if [ "${block_timestamp}" != "${old_block_timestamp}" ]; then + mkdir -p $(dirname "${last_synced_block_file}") + echo ${block_timestamp} > ${last_synced_block_file} +fi + +file_age=$(($(date +%s) - $(date -r ${last_synced_block_file} +%s))); +max_age=${max_lag_in_seconds}; +echo "${last_synced_block_file} age is $file_age seconds. Max healthy age is $max_age seconds"; +if [ ${file_age} -lt ${max_age} ]; then exit 0; else exit 1; fi diff --git a/charts/binancechain/templates/_helpers.tpl b/charts/binancechain/templates/_helpers.tpl new file mode 100644 index 0000000..c463d15 --- /dev/null +++ b/charts/binancechain/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "binancechain.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "binancechain.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "binancechain.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "binancechain.labels" -}} +app.kubernetes.io/name: {{ include "binancechain.name" . }} +helm.sh/chart: {{ include "binancechain.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/charts/binancechain/templates/configmap.yaml b/charts/binancechain/templates/configmap.yaml new file mode 100644 index 0000000..8e9e183 --- /dev/null +++ b/charts/binancechain/templates/configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "{{ .Release.Name }}-scripts" +data: + check_node_health.sh: | + {{- include (print $.Template.BasePath "/_check_node_health.sh") . | nindent 4 }} diff --git a/charts/binancechain/templates/ilb.yaml b/charts/binancechain/templates/ilb.yaml new file mode 100644 index 0000000..17b480b --- /dev/null +++ b/charts/binancechain/templates/ilb.yaml @@ -0,0 +1,29 @@ +{{ if .Values.internalLB }} +## use this to aggregate internal pods behind +## a single load balanced IP +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-ilb + labels: + chain: {{ .Values.binancechain.chain_id }} +{{ include "binancechain.labels" . | indent 4 }} + annotations: + cloud.google.com/load-balancer-type: "Internal" + cloud.google.com/network-tier: "PREMIUM" +spec: + type: LoadBalancer + {{ if .Values.internalLBIP }} + loadBalancerIP: {{ .Values.internalLBIP }} + {{ end }} + ports: + - name: {{ .Values.service.rpcPortName }} + port: {{ .Values.service.rpcPort }} + targetPort: {{ .Values.service.rpcPortName }} + - name: {{ .Values.service.p2pPortName }} + port: {{ .Values.service.p2pPort }} + targetPort: {{ .Values.service.p2pPortName }} + selector: + app.kubernetes.io/name: {{ include "binancechain.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/binancechain/templates/lb-p2p.yaml b/charts/binancechain/templates/lb-p2p.yaml new file mode 100644 index 0000000..c7d49ac --- /dev/null +++ b/charts/binancechain/templates/lb-p2p.yaml @@ -0,0 +1,22 @@ +{{ if .Values.externalLBp2p }} +## use this if you want to expose blockchain p2p (not RPC) to public +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-lb-p2p + labels: + chain: {{ .Values.binancechain.chain_id }} +{{ include "binancechain.labels" . | indent 4 }} +spec: + type: LoadBalancer + {{ if .Values.externalLBp2pIP -}} + loadBalancerIP: {{ .Values.externalLBp2pIP }} + {{ end -}} + ports: + - name: {{ .Values.service.p2pPortName }} + port: {{ .Values.service.p2pPort }} + targetPort: {{ .Values.service.p2pPortName }} + selector: + app.kubernetes.io/name: {{ include "binancechain.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/binancechain/templates/lb.yaml b/charts/binancechain/templates/lb.yaml new file mode 100644 index 0000000..756b18f --- /dev/null +++ b/charts/binancechain/templates/lb.yaml @@ -0,0 +1,32 @@ +{{ if .Values.externalLB }} +## only use this if you want to expose +## json services to a public ip +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-lb + labels: + chain: {{ .Values.binancechain.chain_id }} +{{ include "binancechain.labels" . | indent 4 }} +spec: + type: LoadBalancer + {{ if .Values.externalLBIP }} + loadBalancerIP: {{ .Values.externalLBIP }} + {{ end }} + {{- if .Values.externalLBSourceRanges }} + loadBalancerSourceRanges: + {{- range $val := .Values.externalLBSourceRanges }} + - {{ $val -}} + {{ end }} + {{ end }} + ports: + - name: {{ .Values.service.rpcPortName }} + port: {{ .Values.service.rpcPort }} + targetPort: {{ .Values.service.rpcPortName }} + - name: {{ .Values.service.p2pPortName }} + port: {{ .Values.service.p2pPort }} + targetPort: {{ .Values.service.p2pPortName }} + selector: + app.kubernetes.io/name: {{ include "binancechain.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{ end }} diff --git a/charts/binancechain/templates/secret.yaml b/charts/binancechain/templates/secret.yaml new file mode 100644 index 0000000..a9ac36e --- /dev/null +++ b/charts/binancechain/templates/secret.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Secret +metadata: + name: "{{ .Release.Name }}-env" + labels: +{{ include "binancechain.labels" . | indent 4 }} +type: Opaque +data: + HOME: {{ .Values.binancechain.base_path | b64enc }} + BNET: {{ .Values.binancechain.network | b64enc }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: "{{ .Release.Name }}-config" + labels: +{{ include "binancechain.labels" . | indent 4 }} +type: Opaque +data: + {{ .Values.binancechain.configurationFileName }}: |- + {{- include (print $.Template.BasePath "/_config.toml") . | b64enc | nindent 4 }} + {{ .Values.binancechain.appFileName }}: |- + {{- include (print $.Template.BasePath "/_app.toml") . | b64enc | nindent 4 }} diff --git a/charts/binancechain/templates/service.yaml b/charts/binancechain/templates/service.yaml new file mode 100644 index 0000000..59d1d9a --- /dev/null +++ b/charts/binancechain/templates/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-service + labels: + chain: {{ .Values.binancechain.chain_id }} +{{ include "binancechain.labels" . | indent 4 }} +spec: + ports: + - name: {{ .Values.service.rpcPortName }} + port: {{ .Values.service.rpcPort }} + targetPort: {{ .Values.service.rpcPortName }} + - name: {{ .Values.service.p2pPortName }} + port: {{ .Values.service.p2pPort }} + targetPort: {{ .Values.service.p2pPortName }} + selector: + app.kubernetes.io/name: {{ include "binancechain.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/binancechain/templates/statefulset.yaml b/charts/binancechain/templates/statefulset.yaml new file mode 100644 index 0000000..08b0c1b --- /dev/null +++ b/charts/binancechain/templates/statefulset.yaml @@ -0,0 +1,123 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "binancechain.fullname" . }} + labels: +{{ include "binancechain.labels" . | indent 4 }} +spec: + serviceName: "{{ .Release.Name }}-service" + replicas: {{ .Values.replicaCount }} # by default is 1 + selector: + matchLabels: + app.kubernetes.io/name: {{ include "binancechain.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "binancechain.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + annotations: + checksum/configmap.yaml: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + checksum/secret.yaml: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + spec: + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + envFrom: + - secretRef: + name: "{{ .Release.Name }}-env" + # we have to ignore image entrypoint + command: + - /bin/sh + - -c + - exec /node-binary/fullnode/${BNET}/${BVER}/linux/bnbchaind start --home {{ .Values.binancechain.base_path }} + workingDir: "{{ .Values.binancechain.base_path }}" + resources: + {{- toYaml .Values.resources | nindent 10 }} + ports: + - containerPort: {{ .Values.service.rpcPort }} + name: "{{ .Values.service.rpcPortName }}" + protocol: "TCP" + - containerPort: {{ .Values.service.p2pPort }} + name: "{{ .Values.service.p2pPortName }}" + protocol: "TCP" + volumeMounts: + - name: binancechain-pvc + mountPath: {{ .Values.binancechain.base_path }} + - name: scripts + mountPath: /scripts + livenessProbe: + exec: + command: + - /bin/sh + - /scripts/check_node_health.sh + - "{{ .Values.binancechain.base_path }}" + - "{{ .Values.binancechain.maxHealthyAge }}" + - last_synced_block.txt + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.livenessProbe.failureThreshold }} + initContainers: + {{- if .Values.binancechain_copy_config }} + - name: binancechain-copy-configs + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["/bin/sh", "-c", "mkdir -p {{ .Values.binancechain.base_path }}/{{ .Values.binancechain.config_path }} && cp /node-binary/fullnode/${BNET}/${BVER}/config/genesis.json +{{ .Values.binancechain.base_path }}/{{ .Values.binancechain.config_path }}/genesis.json && cp /config/* {{ .Values.binancechain.base_path }}/{{ .Values.binancechain.config_path }}",] + envFrom: + - secretRef: + name: "{{ .Release.Name }}-env" + volumeMounts: + - name: binancechain-pvc + mountPath: {{ .Values.binancechain.base_path }} + - name: config + mountPath: /config + {{- end }} + volumes: + - name: scripts + configMap: + name: "{{ .Release.Name }}-scripts" + - name: config + secret: + secretName: "{{ .Release.Name }}-config" + volumeClaimTemplates: + - metadata: + name: binancechain-pvc + spec: + accessModes: + - {{.Values.persistence.accessMode }} + {{- if .Values.persistence.storageClass }} + {{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" + {{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" + {{- end }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size }} + volumeMode: Filesystem diff --git a/charts/binancechain/values.yaml b/charts/binancechain/values.yaml new file mode 100755 index 0000000..247864c --- /dev/null +++ b/charts/binancechain/values.yaml @@ -0,0 +1,83 @@ +# Default values for binancechain. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +terminationGracePeriodSeconds: 30 +image: + repository: dysnix/node-binary + tag: fix-dockerfile + pullPolicy: Always + +service: + rpcPortName: jsonrpc + rpcPort: "27147" + p2pPort: "27146" + p2pPortName: p2p + +externalLB: false +externalLBIP: "" +externalLBSourceRanges: {} +# - 203.0.113.2/32 +# - 203.0.113.3/32 + +externalLBp2p: false +externalLBp2pIP: "" +internalLB: false +internalLBIP: "" + +persistence: + enabled: true +# storageClass: "default" + accessMode: ReadWriteOnce + size: "500Gi" + +## Configure resource requests and limits +## ref: http://kubernetes.io/docs/user-guide/compute-resources/ +## +resources: + requests: + cpu: "1000m" + memory: "8200Mi" + limits: + cpu: "6000m" + memory: "10000Mi" + +securityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + +affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchLabels: + app.kubernetes.io/name: "binancechain" + topologyKey: failure-domain.beta.kubernetes.io/zone + +binancechain: + base_path: "/opt/bnbchaind" + config_path: "config" + configurationFileName: "config.toml" + appFileName: "app.toml" + # prod/testnet + network: "prod" + # how many seconds should liveness check wait for a new block. + maxHealthyAge: 3600 + config: + enable_state_sync: false + state_sync_height: -1 + # we don't disable fast sync + #enable_fast_sync: true + + +# enable this to run binancechain-get-genesis as init container +binancechain_copy_config: true + +livenessProbe: + initialDelaySeconds: 600 + periodSeconds: 600 + timeoutSeconds: 500 + successThreshold: 1 + failureThreshold: 2 From 857a87fb4056f6daa9e3c390cf55584208d09305 Mon Sep 17 00:00:00 2001 From: Alex Vorona Date: Thu, 1 Oct 2020 12:00:11 +0300 Subject: [PATCH 5/5] fix README --- charts/binancechain/README.md | 2 +- charts/bitcoind/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/binancechain/README.md b/charts/binancechain/README.md index 34dd20d..d462753 100755 --- a/charts/binancechain/README.md +++ b/charts/binancechain/README.md @@ -41,7 +41,7 @@ The following table lists the configurable parameters of the binancechain chart Parameter | Description | Default ------------------------------- | ------------------------------------------------- | ---------------------------------------------------------- -`image.repository` | Image source repository name | `arilot/docker-binancechain` +`image.repository` | Image source repository name | `dysnix/docker-binancechain` `image.tag` | `binancechain` release tag. | `0.17.1` `image.pullPolicy` | Image pull policy | `IfNotPresent` `service.rpcPort` | RPC port | `8732` diff --git a/charts/bitcoind/README.md b/charts/bitcoind/README.md index 10dd89e..2cdb522 100755 --- a/charts/bitcoind/README.md +++ b/charts/bitcoind/README.md @@ -42,7 +42,7 @@ The following table lists the configurable parameters of the bitcoind chart and Parameter | Description | Default ------------------------------- | ------------------------------------------------- | ---------------------------------------------------------- -`image.repository` | Image source repository name | `arilot/docker-bitcoind` +`image.repository` | Image source repository name | `dysnix/docker-bitcoind` `image.tag` | `bitcoind` release tag. | `0.17.1` `image.pullPolicy` | Image pull policy | `IfNotPresent` `service.rpcPort` | RPC port | `8332`