IBM官方的Fabric on k8s部署方案

IBM官方的Fabric on k8s部署方案

IBM官方提供的fabric在k8s上的部署方案,目前也只看到了solo,该方案可能也只是在测试用的,不同于其它通过nfs共享配置的方式,ibm通过k8s的pv/pvc存储实现共享配置。该方案,基本上上是纯k8s环境,无需其他修改便可直接使用,这点还是很方便的,比自己之前爬坑手动部署要可爱多了。但还有一点不确定,就是ibm是如何实例化代码的,实例化后的容器在哪里,但是服务启动后,多出来一个docker-dind-f4dc8cbf6-lqr66 pod,该pod是否就是实例化后的容器呢?待周末加班结束后,研究一下。

使用ibm方案将fabric部署在k8s上

从IBM/blockchain-network-on-kubernetes,克隆下该工程。

git clone https://github.com/IBM/blockchain-network-on-kubernetes.git
root@hw1:~/blockchain-network-on-kubernetes# ls
artifacts    CONTRIBUTING.md  deleteNetwork.sh  LICENSE         README-cn.md  README.md                      setup_blockchainNetwork_v2.sh
configFiles  DEBUGGING.md     images            MAINTAINERS.md  README-ko.md  setup_blockchainNetwork_v1.sh

先创建k8s集群,这里不再叙述,这里集群已经建立;查看kubectl版本,1.11之前使用脚本1,1.11之后使用脚本2。

root@hw1:~/blockchain-network-on-kubernetes# kubectl version  --short
Client Version: v1.13.1
Server Version: v1.13.1

root@hw1:~/blockchain-network-on-kubernetes# pwd
/root/blockchain-network-on-kubernetes
root@hw1:~/blockchain-network-on-kubernetes# chmod +x setup_blockchainNetwork_v2.sh 

启动脚本,开始部署。这里的链码安装、实例化都是用了k8s的job方式。

root@hw1:~/blockchain-network-on-kubernetes# ./setup_blockchainNetwork_v2.sh 
peersDeployment.yaml file was configured to use Docker in a container.
Creating Docker deployment
persistentvolume/docker-pv created
persistentvolumeclaim/docker-pvc created
service/docker created
deployment.extensions/docker-dind created

Creating new Deployment to create four peers in network
Running: kubectl create -f /root/blockchain-network-on-kubernetes/configFiles/peersDeployment.yaml
deployment.extensions/blockchain-orderer created

Creating channel transaction artifact and a channel
Running: kubectl create -f /root/blockchain-network-on-kubernetes/configFiles/create_channel.yaml
job.batch/createchannel created
Create Channel Completed Successfully

Creating joinchannel job
Running: kubectl create -f /root/blockchain-network-on-kubernetes/configFiles/join_channel.yaml
job.batch/joinchannel created
Join Channel Completed Successfully

Running: kubectl create -f /root/blockchain-network-on-kubernetes/configFiles/chaincode_install.yaml
job.batch/chaincodeinstall created
Chaincode Install Completed Successfully

Creating chaincodeinstantiate job
Running: kubectl create -f /root/blockchain-network-on-kubernetes/configFiles/chaincode_instantiate.yaml
job.batch/chaincodeinstantiate created

Chaincode Instantiation Completed Successfully

Network Setup Completed !!

查看部署后的状态

root@hw1:~/blockchain-network-on-kubernetes# kubectl get pods
NAME                                    READY   STATUS      RESTARTS   AGE
blockchain-ca-54d7b4ddfc-dq94t          1/1     Running     0          38m
blockchain-orderer-67c9ff777d-nsj9n     1/1     Running     0          38m
blockchain-org1peer1-7bd4879446-2c6pf   1/1     Running     0          38m
blockchain-org2peer1-8fc4fbcfc-4q797    1/1     Running     0          38m
blockchain-org3peer1-6cf5d4875f-kb6lt   1/1     Running     0          38m
blockchain-org4peer1-68699bdd8f-g9bm9   1/1     Running     0          38m
chaincodeinstall-8p5pl                  0/4     Completed   0          37m
chaincodeinstantiate-2s9p2              0/1     Completed   0          37m
copyartifacts-6fmvj                     0/1     Completed   0          39m
createchannel-tcxpt                     0/2     Completed   0          38m
docker-dind-f4dc8cbf6-lqr66             1/1     Running     0          40m
joinchannel-9r7t4                       0/4     Completed   0          38m
utils-4h5fc                             0/2     Completed   0          39m
root@hw1:~/blockchain-network-on-kubernetes# kubectl get pvc
NAME         STATUS   VOLUME      CAPACITY   ACCESS MODES   STORAGECLASS   AGE
docker-pvc   Bound    docker-pv   10Gi       RWX                           40m
shared-pvc   Bound    shared-pv   1Gi        RWX                           39m
root@hw1:~/blockchain-network-on-kubernetes# kubectl get pv
NAME        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS   REASON   AGE
docker-pv   10Gi       RWX            Retain           Bound    default/docker-pvc                           40m
shared-pv   1Gi        RWX            Retain           Bound    default/shared-pvc                           39m

测试,进入org1.peer1 pod,查询和调用链码。

查询,这里使用的通道名为channel1,结果为100。

root@blockchain-org1peer1-7bd4879446-2c6pf:/# peer chaincode query -C channel1 -n cc -c '{"Args":["query","a"]}'
2019-05-11 08:55:48.397 UTC [viperutil] getKeysRecursively -> DEBU 001 Found map[string]interface{} value for peer.BCCSP
...
2019-05-11 08:55:48.415 UTC [msp.identity] Sign -> DEBU 043 Sign: plaintext: 0AA8070A6408031A0C08949CDAE60510...120263631A0A0A0571756572790A0161 
2019-05-11 08:55:48.415 UTC [msp.identity] Sign -> DEBU 044 Sign: digest: DA4C939594E3236D6CA91E77FF22C7E3C8CB5B89A84EE7CAFB78418221764499 
100

调用链码,a向b转20;查询调用后的结果,a为80。

root@blockchain-org1peer1-7bd4879446-2c6pf:/# peer chaincode invoke -o blockchain-orderer:31010 -C channel1 -n cc -c '{"Args":["invoke","a","b","20"]}'
2019-05-11 08:56:10.741 UTC [viperutil] getKeysRecursively -> DEBU 001 Found map[string]interface{} value for peer.BCCSP
...
2019-05-11 08:56:10.761 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 04e Chaincode invoke successful. result: status:200

root@blockchain-org1peer1-7bd4879446-2c6pf:/# peer chaincode query -C channel1 -n cc -c '{"Args":["query","a"]}'
2019-05-11 09:26:05.412 UTC [viperutil] getKeysRecursively -> DEBU 001 Found map[string]interface{} value for peer.BCCSP
2019-05-11 09:26:05.412 UTC [viperutil] getKeysRecursively -> DEBU 002 Found map[string]interface{} value for peer.BCCSP.PKCS11
...
80

参考:

  1. IBM/blockchain-network-on-kubernetes
  2. 在本地 kubernetes 上快速部署 Hyperledger Fabric 网络

你可能感兴趣的:(云计算/大数据,区块链,kubernetes,Hyperledger,Fabric)