apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: "<name>"
spec:
  serviceName: "<name>"
  selector:
    matchLabels:
      k8s-app: "<name>"
      type: peer
  replicas: 1
  volumeClaimTemplates:
  - metadata:
      name: peerstorage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "default"
      resources:
        requests:
          storage: "1Gi"
  template:
    metadata:
      labels:
        k8s-app: "<name>"
        type: "peer"
        component: "peer"
    spec:
      volumes:
        - name: peercerts
          secret:
            secretName: peercerts
        - name: toolset
          configMap:
            name: fabric-toolset
        - name: rundind
          emptyDir:
            medium: Memory
      initContainers:
        - name: init
          image: "hfrd/envsubst:latest"
          volumeMounts:
          - mountPath: "/var/peer"
            name: peerstorage
          - mountPath: "/toolset"
            name: toolset
          - mountPath: "/certs"
            name: peercerts
          command: ["/bin/bash"]
          args:  ["/toolset/peer_config.sh"]
      containers:
        - name: peer
          image: "<image>"
          imagePullPolicy: Always
          env:
          - { name: "CORE_PEER_LOCALMSPID", valueFrom: { secretKeyRef: { name: "<TobeReplaced>", key: "mspid" }}}
          - { name: "CORE_PEER_MSPCONFIGPATH", value: "/etc/hyperledger/fabric/msp" }
          - { name: "CORE_VM_ENDPOINT", value: "unix:///var/run/docker.sock" }
          - { name: "FABRIC_LOGGING_SPEC", value: "ERROR" }
          volumeMounts:
          - mountPath: "/var/hyperledger/production"
            name: peerstorage
            subPath: production
          - mountPath: "/etc/hyperledger/fabric/msp"
            name: peerstorage
            subPath: msp
          - mountPath: "/etc/hyperledger/fabric/tls"
            name: peerstorage
            subPath: tls
          - mountPath: "/var/run"
            name: rundind
          command: ["peer"]
          args:  ["node", "start"]
        - name: dind
          image: docker:dind
          securityContext:
            privileged: true
          args:
            - dockerd
            - -H unix:///var/run/docker.sock
          volumeMounts:
            - name: rundind
              mountPath: /var/run