github.com/franono/tendermint@v0.32.2-0.20200527150959-749313264ce9/tools/mintnet-kubernetes/examples/basecoin/app.yaml (about)

     1  ---
     2  apiVersion: v1
     3  kind: Service
     4  metadata:
     5    annotations:
     6      service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
     7    name: basecoin
     8    labels:
     9      app: basecoin
    10  spec:
    11    ports:
    12    - port: 26656
    13      name: p2p
    14    - port: 26657
    15      name: rpc
    16    clusterIP: None
    17    selector:
    18      app: tm
    19  ---
    20  apiVersion: v1
    21  kind: ConfigMap
    22  metadata:
    23    name: tm-config
    24  data:
    25    seeds: "tm-0,tm-1,tm-2,tm-3"
    26    validators: "tm-0,tm-1,tm-2,tm-3"
    27    validator.power: "10"
    28    genesis.json: |-
    29      {
    30        "genesis_time": "2016-02-05T06:02:31.526Z",
    31        "chain_id": "chain-tTH4mi",
    32        "validators": [],
    33        "app_hash": ""
    34      }
    35    pub_key_nginx.conf: |-
    36      server {
    37        listen 80 default_server;
    38        listen [::]:80 default_server ipv6only=on;
    39        location /pub_key.json { root /usr/share/nginx/; }
    40        location /app_pub_key.json { root /usr/share/nginx/; }
    41      }
    42  ---
    43  apiVersion: v1
    44  kind: ConfigMap
    45  metadata:
    46    name: app-config
    47  data:
    48    genesis.json: |-
    49      {
    50        "chain_id": "chain-tTH4mi",
    51        "app_options": {
    52          "accounts": [
    53            {
    54              "pub_key": "tm-0",
    55              "coins": [
    56                {
    57                  "denom": "mycoin",
    58                  "amount": 1000000000
    59                }
    60              ]
    61            },
    62            {
    63              "pub_key": "tm-1",
    64              "coins": [
    65                {
    66                  "denom": "mycoin",
    67                  "amount": 1000000000
    68                }
    69              ]
    70            },
    71            {
    72              "pub_key": "tm-2",
    73              "coins": [
    74                {
    75                  "denom": "mycoin",
    76                  "amount": 1000000000
    77                }
    78              ]
    79            },
    80            {
    81              "pub_key": "tm-3",
    82              "coins": [
    83                {
    84                  "denom": "mycoin",
    85                  "amount": 1000000000
    86                }
    87              ]
    88            }
    89          ]
    90        }
    91      }
    92  ---
    93  apiVersion: policy/v1beta1
    94  kind: PodDisruptionBudget
    95  metadata:
    96    name: tm-budget
    97  spec:
    98    selector:
    99      matchLabels:
   100        app: tm
   101    minAvailable: 2
   102  ---
   103  apiVersion: apps/v1beta1
   104  kind: StatefulSet
   105  metadata:
   106    name: tm
   107  spec:
   108    serviceName: basecoin
   109    replicas: 4
   110    template:
   111      metadata:
   112        labels:
   113          app: tm
   114        annotations:
   115          pod.beta.kubernetes.io/init-containers: '[{
   116            "name": "tm-gen-validator",
   117            "image": "franono/tendermint:0.10.0",
   118            "imagePullPolicy": "IfNotPresent",
   119            "command": ["bash", "-c", "
   120              set -ex\n
   121              if [ ! -f /tendermint/priv_validator.json ]; then\n
   122                tendermint gen_validator > /tendermint/priv_validator.json\n
   123                # pub_key.json will be served by pub-key container\n
   124                cat /tendermint/priv_validator.json | jq \".pub_key\" > /tendermint/pub_key.json\n
   125              fi\n
   126            "],
   127            "volumeMounts": [
   128              {"name": "tmdir", "mountPath": "/tendermint"}
   129            ]
   130          },
   131          {
   132            "name": "app-gen-key",
   133            "image": "tendermint/basecoin:0.5.1",
   134            "imagePullPolicy": "IfNotPresent",
   135            "command": ["bash", "-c", "
   136              set -ex\n
   137              if [ ! -f /app/key.json ]; then\n
   138                basecoin key new > /app/key.json\n
   139                # pub_key.json will be served by app-pub-key container\n
   140                cat /app/key.json | jq \".pub_key\" > /app/pub_key.json\n
   141              fi\n
   142            "],
   143            "volumeMounts": [
   144              {"name": "appdir", "mountPath": "/app"}
   145            ]
   146          }]'
   147      spec:
   148        containers:
   149        - name: tm
   150          imagePullPolicy: IfNotPresent
   151          image: franono/tendermint:0.10.0
   152          ports:
   153          - containerPort: 26656
   154            name: p2p
   155          - containerPort: 26657
   156            name: rpc
   157          env:
   158          - name: SEEDS
   159            valueFrom:
   160              configMapKeyRef:
   161                name: tm-config
   162                key: seeds
   163          - name: VALIDATOR_POWER
   164            valueFrom:
   165              configMapKeyRef:
   166                name: tm-config
   167                key: validator.power
   168          - name: VALIDATORS
   169            valueFrom:
   170              configMapKeyRef:
   171                name: tm-config
   172                key: validators
   173          - name: TMHOME
   174            value: /tendermint
   175          command:
   176          - bash
   177          - "-c"
   178          - |
   179            set -ex
   180  
   181            # copy template
   182            cp /etc/tendermint/genesis.json /tendermint/genesis.json
   183  
   184            # fill genesis file with validators
   185            IFS=',' read -ra VALS_ARR <<< "$VALIDATORS"
   186            fqdn_suffix=$(hostname -f | sed 's#[^.]*\.\(\)#\1#')
   187            for v in "${VALS_ARR[@]}"; do
   188              # wait until validator generates priv/pub key pair
   189              set +e
   190  
   191              curl -s --fail "http://$v.$fqdn_suffix/pub_key.json" > /dev/null
   192              ERR=$?
   193              while [ "$ERR" != 0 ]; do
   194                sleep 5
   195                curl -s --fail "http://$v.$fqdn_suffix/pub_key.json" > /dev/null
   196                ERR=$?
   197              done
   198              set -e
   199  
   200              # add validator to genesis file along with its pub_key
   201              curl -s "http://$v.$fqdn_suffix/pub_key.json" | jq ". as \$k | {pub_key: \$k, amount: $VALIDATOR_POWER, name: \"$v\"}" > pub_validator.json
   202              cat /tendermint/genesis.json | jq ".validators |= .+ [$(cat pub_validator.json)]" > tmpgenesis && mv tmpgenesis /tendermint/genesis.json
   203              rm pub_validator.json
   204            done
   205  
   206            # construct seeds
   207            IFS=',' read -ra SEEDS_ARR <<< "$SEEDS"
   208            seeds=()
   209            for s in "${SEEDS_ARR[@]}"; do
   210              seeds+=("$s.$fqdn_suffix:26656")
   211            done
   212            seeds=$(IFS=','; echo "${seeds[*]}")
   213  
   214            tendermint node --p2p.seeds="$seeds" --moniker="`hostname`" --proxy_app="unix:///socks/app.sock"
   215          volumeMounts:
   216          - name: tmdir
   217            mountPath: /tendermint
   218          - mountPath: /etc/tendermint/genesis.json
   219            name: tmconfigdir
   220            subPath: genesis.json
   221          - name: socksdir
   222            mountPath: /socks
   223  
   224        - name: app
   225          imagePullPolicy: IfNotPresent
   226          image: tendermint/basecoin:0.5.1
   227          env:
   228          - name: BCHOME
   229            value: /app
   230          workingDir: /app
   231          command:
   232          - bash
   233          - "-c"
   234          - |
   235            set -ex
   236  
   237            # replace "tm-N" with public keys in genesis file
   238            cp /etc/app/genesis.json genesis.json
   239            fqdn_suffix=$(hostname -f | sed 's#[^.]*\.\(\)#\1#')
   240            # for every "base/account"
   241            i=0
   242            length=$(cat genesis.json | jq ".app_options.accounts | length")
   243            while [[ $i -lt $length ]]; do
   244              # extract pod name ("tm-0")
   245              pod=$(cat genesis.json | jq -r ".app_options.accounts[$i].pub_key")
   246  
   247              # wait until pod starts to serve its pub_key
   248              set +e
   249  
   250              curl -s --fail "http://$pod.$fqdn_suffix/app_pub_key.json" > /dev/null
   251              ERR=$?
   252              while [ "$ERR" != 0 ]; do
   253                sleep 5
   254                curl -s --fail "http://$pod.$fqdn_suffix/app_pub_key.json" > /dev/null
   255                ERR=$?
   256              done
   257              set -e
   258  
   259              # get its pub_key
   260              curl -s "http://$pod.$fqdn_suffix/app_pub_key.json" | jq "." > k.json
   261  
   262              # replace pod name with it ("tm-0" => "{"type": ..., "data": ...}")
   263              cat genesis.json | jq ".app_options.accounts[$i].pub_key = $(cat k.json | jq '.')" > tmpgenesis && mv tmpgenesis genesis.json
   264              rm -f k.json
   265  
   266              i=$((i+1))
   267            done
   268  
   269            rm -f /socks/app.sock # remove old socket
   270  
   271            basecoin start --address="unix:///socks/app.sock" --without-tendermint
   272          volumeMounts:
   273          - name: appdir
   274            mountPath: /app
   275          - mountPath: /etc/app/genesis.json
   276            name: appconfigdir
   277            subPath: genesis.json
   278          - name: socksdir
   279            mountPath: /socks
   280  
   281        - name: pub-key
   282          imagePullPolicy: IfNotPresent
   283          image: nginx:latest
   284          ports:
   285          - containerPort: 80
   286          command:
   287          - bash
   288          - "-c"
   289          - |
   290            set -ex
   291            # fixes 403 Permission Denied (open() "/tendermint/pub_key.json" failed (13: Permission denied))
   292            # => we cannot serve from /tendermint, so we copy the file
   293            mkdir -p /usr/share/nginx
   294            cp /tendermint/pub_key.json /usr/share/nginx/pub_key.json
   295            cp /app/pub_key.json /usr/share/nginx/app_pub_key.json
   296            nginx -g "daemon off;"
   297          volumeMounts:
   298          - name: tmdir
   299            mountPath: /tendermint
   300          - name: appdir
   301            mountPath: /app
   302          - mountPath: /etc/nginx/conf.d/pub_key.conf
   303            name: tmconfigdir
   304            subPath: pub_key_nginx.conf
   305  
   306        volumes:
   307        - name: tmconfigdir
   308          configMap:
   309            name: tm-config
   310        - name: appconfigdir
   311          configMap:
   312            name: app-config
   313        - name: socksdir
   314          emptyDir: {}
   315  
   316    volumeClaimTemplates:
   317    - metadata:
   318        name: tmdir
   319        annotations:
   320          volume.alpha.kubernetes.io/storage-class: anything
   321      spec:
   322        accessModes: [ "ReadWriteOnce" ]
   323        resources:
   324          requests:
   325            storage: 2Gi
   326    - metadata:
   327        name: appdir
   328        annotations:
   329          volume.alpha.kubernetes.io/storage-class: anything
   330      spec:
   331        accessModes: [ "ReadWriteOnce" ]
   332        resources:
   333          requests:
   334            storage: 12Mi