hyperledger-fabric-with-k8s

Download fabric tools

docker pull hyperledger/fabric-tools:1.2.1 docker pull hyperledger/fabric-couchdb:0.4.10 docker pull hyperledger/fabric-orderer:1.4.0 docker pull hyperledger/fabric-peer:1.4.0 docker pull hyperledger/fabric-ca:1.4.0

create couchdb

listen: 5984, 30005 srv: 10.98.81.63 ip: 172.17.0.4

create CA

listen: 7054 srv: 10.111.251.3 ip: 172.17.0.7

create orderer

listen: srv: 10.98.135.207 ip: 172.17.0.8

create peer (depend on CA + orderer)

listen: 7051, 7052, 7053 srv: 10.106.27.9

Create channel

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/chaincode/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp
export CORE_PEER_LOCALMSPID="Org1MSP"
export CHANNEL_NAME=composerchannel
export CORE_PEER_NETWORKID="nid1"
peer channel create -o orderer.example.com:7050 -c composerchannel -f ./composer-channel.tx

peer channel fetch newest -o orderer.example.com:7050 -c composerchannel

peer channel join -b composerchannel.block
# peer channel create -o orderer.example.com:7050 -c mychannel -f ./composer-channel.tx

Join Channel

#join channel
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/chaincode/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp
export CHANNEL_NAME=composerchannel
export CORE_PEER_LOCALMSPID="Org1MSP" #this matters
export CORE_PEER_MSPID="Org1MSP"

peer channel fetch newest -o orderer.example.com:7050 -c ${CHANNEL_NAME}
peer channel join -b ${CHANNEL_NAME}_newest.block

Install chaincode

cp -r chaincode_example02/ $GOPATH/src

export CHAINCODE_NAME="exam2_1"
export CHAINCODE_VERSION="2.0"

peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/

Instantiate Chaincode

export ORDERER_URL=orderer.example.com:7050
export CHANNEL_NAME=composerchannel

peer chaincode instantiate -o ${ORDERER_URL} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -P "AND('Org1MSP.member')" -c '{"Args":["init","a","400","b","300"]}'

Query

peer chaincode invoke --peerAddresses peer0.org1.example.com:7051 -o ${ORDERER_URL} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -c '{"Args":["invoke","a","b","50"]}'

peer chaincode invoke -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -c '{"Args":["invoke","c","d","50"]}'

peer chaincode query -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -c '{"Args":["query","a"]}'

Ref

  1. NodeJS chaincode shim https://fabric-shim.github.io/release-1.4/fabric-shim.ChaincodeInterface.html?redirect=true
  2. https://jicki.me/fabric,kubernetes/2019/01/21/hyperledger-fabric-1.4-to-k8s/
  3. https://opensource.com/article/18/4/deploying-hyperledger-fabric-kubernetes
  4. https://github.com/hainingzhang/articles
  5. http://www.think-foundry.com/deploy-hyperledger-fabric-on-kubernetes-part-2/
  6. https://github.com/feitnomore/hyperledger-fabric-kubernetes
  7. https://www.lijiaocn.com/问题/2018/04/25/hyperledger-fabric-problem.html#创建channel时失败failed-to-reach-implicit-threshold-of-1-sub-policies-required-1-remaining
  8. using dev mode https://hyperledger-fabric.readthedocs.io/en/release-1.4/peer-chaincode-devmode.html

utils

install ping

apt-get update && apt-get install -y iputils-ping

commit images

docker commit -a “chiban” -m “add ping” 21758ff79079 hyperledger/fabric-tools:1.2.1-c

if port is open?

cat </dev/tcp/peer0.org1.example.com/7052