#apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
  name: geth
  labels:
    app: geth
spec:
  replicas: 1
  selector:
    matchLabels:
      app: geth
  template:
    metadata:
      labels:
        app: geth
        name: geth          
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
        scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
    spec:
      serviceAccount: default
      containers:
      - name: geth
        image: ethereum/client-go
        ports:
        - containerPort: 8545
        - containerPort: 30303
        args:
        - "--datadir=/var/geth"
        - "--networkid=15"
        - "--rpc"
        - "--rpcaddr=0.0.0.0"
        - "--rpcapi=admin,db,eth,debug,miner,net,shh,txpool,personal,web3"
        - "--rpccorsdomain=*"
        - "--rpcvhosts=*"
        - "--allow-insecure-unlock"
        # - "-verbosity=6"
        resources:
          requests:
            cpu: 100m
        volumeMounts:
        - name: geth-data
          mountPath: /var/geth
        livenessProbe:
          httpGet:
            path: /
            port: 8545
          initialDelaySeconds: 15
          timeoutSeconds: 5
      - name: geth-ethnetintel
        image: kairen/ethnetintel
        env:
        - name: NAME_PREFIX
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: WS_SERVER
          value: "ethstats-dashboard.default.svc.cluster.local:3000"
        - name: WS_SECRET
          value: "12qw34er"
        - name: RPC_HOST
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: RPC_PORT
          value: "8545"
      - name: geth-auto-peer
        image: kairen/auto-peer
        env:
        - name: SERVICE_NAME
          value: "geth"
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        command: [ "/bin/sh", "-c" ]
        args:
        - "set -e -x; while true; do python /etc/auto_peer.py; sleep 15; done;"
      # init genesis data
      initContainers:
      - name: init-genesis
        image: ethereum/client-go
        args:
        - "init"
        - "--datadir=/var/geth"
        - "/etc/geth/genesis.json"
        volumeMounts:
        - name: geth-data
          mountPath: /var/geth
        - name: genesis-cfg
          mountPath: /etc/geth/
      volumes:
      - name: genesis-cfg
        configMap:
          name: geth-config
      - name: geth-data
        hostPath:
          path: /var/geth
      # store to nfs pv
      # - name: geth-data
      #   persistentVolumeClaim:
      #     claimName: geth-pvc
