Chaincode instantiation fails in AWS EKS network

12/11/2019

I have a simple one orderer and one peer network deployed on AWS-Elastic Kubernetes Services. I created the network using the official eks documentation. I am able to bring up the orderer as well as the peer within the pods. The peer is able to create and join the channel as well as anchor peer update transaction is successful as well.

High-level configuration for the pods:

  1. Started as Stateful Sets
  2. Pods use dynamic PV with Storage Class configured for aws-ebs
  3. Exposed using service type load balancer
  4. Uses Docker In Docker(DIND) approach for chaincode

Detailed Configuration for Orderer Pod:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: allparticipants-orderer
  labels:
    app: allparticipants-orderer
spec:
  serviceName: orderer
  replicas: 1
  selector:
    matchLabels:
      app: allparticipants-orderer
  template:
    metadata:
      labels:
        app: allparticipants-orderer
    spec:
      containers:
      - name: allparticipants-orderer
        image: <docker-hub-url>/orderer:0.1
        imagePullPolicy: Always
        command: ["sh", "-c", "orderer"]
        ports:
          - containerPort: 7050
        env:
          - name: FABRIC_LOGGING_SPEC
            value: DEBUG
          - name: ORDERER_GENERAL_LOGLEVEL
            value: DEBUG
          - name: ORDERER_GENERAL_LISTENADDRESS
            value: 0.0.0.0
          - name: ORDERER_GENERAL_GENESISMETHOD
            value: file
          - name: ORDERER_GENERAL_GENESISFILE
            value: /var/hyperledger/orderer/orderer.genesis.block
          - name: ORDERER_GENERAL_LOCALMSPID
            value: OrdererMSP
          - name: ORDERER_GENERAL_LOCALMSPDIR
            value: /var/hyperledger/orderer/msp
          - name: ORDERER_GENERAL_TLS_ENABLED
            value: "false"
          - name: ORDERER_GENERAL_TLS_PRIVATEKEY
            value: /var/hyperledger/orderer/tls/server.key
          - name: ORDERER_GENERAL_TLS_CERTIFICATE
            value: /var/hyperledger/orderer/tls/server.crt
          - name: ORDERER_GENERAL_TLS_ROOTCAS
            value: /var/hyperledger/orderer/tls/ca.crt
        volumeMounts:
        - name: allparticipants-orderer-ledger
          mountPath: /var/ledger

  volumeClaimTemplates:
  - metadata: 
      name: allparticipants-orderer-ledger
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: allparticipants-orderer-sc
      resources:
        requests:
          storage: 1Gi

Detailed configuration for Peer along with DIND in the same pod:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: allparticipants-peer0
  labels:
    app: allparticipants-peer0
spec:
  serviceName: allparticipants-peer0
  replicas: 1
  selector:
    matchLabels:
      app: allparticipants-peer0
  template:
    metadata:
      labels:
        app: allparticipants-peer0
    spec:
      containers:
      - name: docker
        env:
          - name: DOCKER_TLS_CERTDIR
            value:
        securityContext:
          privileged: true
        image: "docker:stable-dind"
        ports:
          - containerPort: 2375
        volumeMounts:
          - mountPath: /var/lib/docker
            name: dockervolume
      - name: allparticipants-peer0
        image: <docker-hub-url>/peer0:0.1
        imagePullPolicy: Always
        command: ["sh", "-c", "peer node start"]
        ports:
          - containerPort: 7051
        env:
          - name: CORE_VM_ENDPOINT
            value: http://localhost:2375
          - name: CORE_PEER_CHAINCODELISTENADDRESS
            value: 0.0.0.0:7052
          - name: FABRIC_LOGGING_SPEC
            value: debug
          - name: CORE_LOGGING_PEER
            value: debug
          - name: CORE_LOGGING_CAUTHDSL
            value: debug
          - name: CORE_LOGGING_GOSSIP
            value: debug
          - name: CORE_LOGGING_LEDGER
            value: debug
          - name: CORE_LOGGING_MSP
            value: info
          - name: CORE_LOGGING_POLICIES
            value: debug
          - name: CORE_LOGGING_GRPC
            value: debug
          - name: CORE_LEDGER_STATE_STATEDATABASE
            value: goleveldb
          - name: GODEBUG
            value: "netdns=go"
          - name: CORE_PEER_TLS_ENABLED
            value: "false"
          - name: CORE_PEER_GOSSIP_USELEADERELECTION
            value: "true"
          - name: CORE_PEER_GOSSIP_ORGLEADER
            value: "false"
          - name: CORE_PEER_GOSSIP_SKIPHANDSHAKE
            value: "true"
          - name: CORE_PEER_PROFILE_ENABLED
            value: "true"
          - name: CORE_PEER_COMMITTER_ENABLED
            value: "true"
          - name: CORE_PEER_TLS_CERT_FILE
            value: /etc/hyperledger/fabric/tls/server.crt
          - name: CORE_PEER_TLS_KEY_FILE
            value: /etc/hyperledger/fabric/tls/server.key
          - name: CORE_PEER_TLS_ROOTCERT_FILE
            value: /etc/hyperledger/fabric/tls/ca.crt
          - name: CORE_PEER_ID
            value: allparticipants-peer0
          - name: CORE_PEER_ADDRESS
            value: <peer0-load-balancer-url>:7051
          - name: CORE_PEER_LISTENADDRESS
            value: 0.0.0.0:7051
          - name: CORE_PEER_EVENTS_ADDRESS
            value: 0.0.0.0:7053
          - name: CORE_PEER_GOSSIP_BOOTSTRAP
            value: <peer0-load-balancer-url>:7051
          - name: CORE_PEER_GOSSIP_EXTERNALENDPOINT
            value: <peer0-load-balancer-url>:7051
          - name: CORE_PEER_LOCALMSPID
            value: AllParticipantsMSP
          - name: CORE_PEER_MSPCONFIGPATH
            value: <path-to-msp-of-peer0>
          - name: ORDERER_ADDRESS
            value: <orderer-load-balancer-url>:7050
          - name: CORE_PEER_ADDRESSAUTODETECT
            value: "true"
          - name: CORE_VM_DOCKER_ATTACHSTDOUT
            value: "true"
          - name: FABRIC_CFG_PATH
            value: /etc/hyperledger/fabric
        volumeMounts:
        - name: allparticipants-peer0-ledger
          mountPath: /var/ledger
        - name: dockersock
          mountPath: /host/var/run/docker.sock
      volumes:
      - name: dockersock
        hostPath:
          path: /var/run/docker.sock
      - name: dockervolume
        persistentVolumeClaim:
          claimName: docker-pvc
  volumeClaimTemplates:
  - metadata: 
      name: allparticipants-peer0-ledger
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: allparticipants-peer0-sc
      resources:
        requests:
          storage: 1Gi

Not including Storage Class and Service configuration for the pods as they seem to work fine.

So, as stated earlier, the peer is able to create and join the channel as well as I am able to install the chaincode in the peer. However, while instantiating the chaincode from within the peer, I get the following error:

Error: error endorsing chaincode: rpc error: code = Unavailable desc = transport is closing

Apart from this the Docker(DIND) container started within peer0's pod has following warning logs:

level=warning msg="887409d917bd7ef74ebe8617b8dcbedc8197741662a14b988491c54085e9acfd cleanup: failed to unmount IPC: umount /var/lib/docker/containers/887409d917bd7ef74ebe8617b8dcbedc8197741662a14b988491c54085e9acfd/mounts/shm, flags: 0x2: no such file or directory"

Additionally, there are no logs in this docker container when I submit the following instantiation request:

peer chaincode instantiate -o $ORDERER_ADDRESS -C carchannel -n fabcar
-l node -v 0.1.1 -c '{"Args":[]}' -P "OR ('AllParticipantsMSP.member','AllParticipantsMSP.peer', 'AllParticipantsMSP.admin', 'AllParticipantsMSP.client')"

I tried searching for similar issues but not able to find one that matches this eks one.

Is there an issue with pod configuration or eks configuration? Not able to get past this one. Can someone please point me in the right direction? I am quite new to K8s.

Update 1:

I updated the service type to Load Balancer keeping rest of the configurations similar. Still I get the same error.

Update 2:

Configured DIND approach for the chaincode container.

Update 3:

Mounted pv and pvc for the dind container as well as updated the CORE_VM_ENDPOINT access protocol from tcp to http.

-- Mrudav Shukla
aws-eks
hyperledger-fabric
kubernetes

1 Answer

12/17/2019

The issue here was the image used for Docker In Docker container. I downgraded the docker-in-docker image version from docker:stable-dind one to docker:18-dind. The stable image version has TLS enabled by default. In my case, I tried setting the value of the environment variable DOCKER_TLS_CERTDIR to blank. But that did not work out.

Attaching the snippet of the DIND configuration:

containers:
  - name: docker
    securityContext:
      privileged: true
    image: "docker:18-dind"
    ports:
      - containerPort: 2375
        protocol: TCP
    volumeMounts:
      - mountPath: /var/lib/docker
        name: dockervolume

Note: While I have been able to work this out, I am not marking this as the accepted answer since TLS might be required to instantiate the chaincode and there should be a way to use that and I would be open to and looking out for those answers.

-- Mrudav Shukla
Source: StackOverflow