github.com/vipernet-xyz/tm@v0.34.24/tools/mintnet-kubernetes/examples/counter/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: counter
     8    labels:
     9      app: counter
    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-05T23:17:31.164Z",
    31        "chain_id": "chain-B5XXm5",
    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      }
    41  ---
    42  apiVersion: policy/v1beta1
    43  kind: PodDisruptionBudget
    44  metadata:
    45    name: tm-budget
    46  spec:
    47    selector:
    48      matchLabels:
    49        app: tm
    50    minAvailable: 2
    51  ---
    52  apiVersion: apps/v1beta1
    53  kind: StatefulSet
    54  metadata:
    55    name: tm
    56  spec:
    57    serviceName: counter
    58    replicas: 4
    59    template:
    60      metadata:
    61        labels:
    62          app: tm
    63        annotations:
    64          pod.beta.kubernetes.io/init-containers: '[{
    65            "name": "tm-gen-validator",
    66            "image": "tendermint/tendermint:0.10.0",
    67            "imagePullPolicy": "IfNotPresent",
    68            "command": ["bash", "-c", "
    69              set -ex\n
    70              if [ ! -f /tendermint/priv_validator.json ]; then\n
    71                tendermint gen_validator > /tendermint/priv_validator.json\n
    72                # pub_key.json will be served by pub-key container\n
    73                cat /tendermint/priv_validator.json | jq \".pub_key\" > /tendermint/pub_key.json\n
    74              fi\n
    75            "],
    76            "volumeMounts": [
    77              {"name": "tmdir", "mountPath": "/tendermint"}
    78            ]
    79          }]'
    80      spec:
    81        containers:
    82        - name: tm
    83          imagePullPolicy: IfNotPresent
    84          image: tendermint/tendermint:0.10.0
    85          ports:
    86          - containerPort: 26656
    87            name: p2p
    88          - containerPort: 26657
    89            name: rpc
    90          env:
    91          - name: SEEDS
    92            valueFrom:
    93              configMapKeyRef:
    94                name: tm-config
    95                key: seeds
    96          - name: VALIDATOR_POWER
    97            valueFrom:
    98              configMapKeyRef:
    99                name: tm-config
   100                key: validator.power
   101          - name: VALIDATORS
   102            valueFrom:
   103              configMapKeyRef:
   104                name: tm-config
   105                key: validators
   106          - name: TMHOME
   107            value: /tendermint
   108          command:
   109          - bash
   110          - "-c"
   111          - |
   112            set -ex
   113  
   114            # copy template
   115            cp /etc/tendermint/genesis.json /tendermint/genesis.json
   116  
   117            # fill genesis file with validators
   118            IFS=',' read -ra VALS_ARR <<< "$VALIDATORS"
   119            fqdn_suffix=$(hostname -f | sed 's#[^.]*\.\(\)#\1#')
   120            for v in "${VALS_ARR[@]}"; do
   121              # wait until validator generates priv/pub key pair
   122              set +e
   123  
   124              curl -s --fail "http://$v.$fqdn_suffix/pub_key.json" > /dev/null
   125              ERR=$?
   126              while [ "$ERR" != 0 ]; do
   127                sleep 5
   128                curl -s --fail "http://$v.$fqdn_suffix/pub_key.json" > /dev/null
   129                ERR=$?
   130              done
   131              set -e
   132  
   133              # add validator to genesis file along with its pub_key
   134              curl -s "http://$v.$fqdn_suffix/pub_key.json" | jq ". as \$k | {pub_key: \$k, amount: $VALIDATOR_POWER, name: \"$v\"}" > pub_validator.json
   135              cat /tendermint/genesis.json | jq ".validators |= .+ [$(cat pub_validator.json)]" > tmpgenesis && mv tmpgenesis /tendermint/genesis.json
   136              rm pub_validator.json
   137            done
   138  
   139            # construct seeds
   140            IFS=',' read -ra SEEDS_ARR <<< "$SEEDS"
   141            seeds=()
   142            for s in "${SEEDS_ARR[@]}"; do
   143              seeds+=("$s.$fqdn_suffix:26656")
   144            done
   145            seeds=$(IFS=','; echo "${seeds[*]}")
   146  
   147            tendermint node --p2p.seeds="$seeds" --moniker="`hostname`" --proxy_app="unix:///socks/app.sock"
   148          volumeMounts:
   149          - name: tmdir
   150            mountPath: /tendermint
   151          - mountPath: /etc/tendermint/genesis.json
   152            name: tmconfigdir
   153            subPath: genesis.json
   154          - name: socksdir
   155            mountPath: /socks
   156  
   157        - name: app
   158          imagePullPolicy: IfNotPresent
   159          image: golang:latest
   160          command:
   161          - bash
   162          - "-c"
   163          - |
   164            set -ex
   165  
   166            go get github.com/vipernet-xyz/tm/abci/cmd/abci-cli
   167  
   168            rm -f /socks/app.sock # remove old socket
   169  
   170            abci-cli counter --serial=true --address="unix:///socks/app.sock"
   171          volumeMounts:
   172          - name: socksdir
   173            mountPath: /socks
   174  
   175        - name: pub-key
   176          imagePullPolicy: IfNotPresent
   177          image: nginx:latest
   178          ports:
   179          - containerPort: 80
   180            name: pub-key
   181          command:
   182          - bash
   183          - "-c"
   184          - |
   185            set -ex
   186            # fixes 403 Permission Denied (open() "/tendermint/pub_key.json" failed (13: Permission denied))
   187            # => we cannot serve from /tendermint, so we copy the file
   188            mkdir -p /usr/share/nginx
   189            cp /tendermint/pub_key.json /usr/share/nginx/pub_key.json
   190            nginx -g "daemon off;"
   191          volumeMounts:
   192          - name: tmdir
   193            mountPath: /tendermint
   194          - mountPath: /etc/nginx/conf.d/pub_key.conf
   195            name: tmconfigdir
   196            subPath: pub_key_nginx.conf
   197  
   198        volumes:
   199        - name: tmconfigdir
   200          configMap:
   201            name: tm-config
   202        - name: socksdir
   203          emptyDir: {}
   204  
   205    volumeClaimTemplates:
   206    - metadata:
   207        name: tmdir
   208        annotations:
   209          volume.alpha.kubernetes.io/storage-class: anything
   210      spec:
   211        accessModes: ["ReadWriteOnce"]
   212        resources:
   213          requests:
   214            storage: 2Gi