Connecting remotly a blockchain made with Hyperledger Fabric 1.4 running with Kubernetes

10/7/2019

I have a Hyperledger Fabric 1.4 blockchain running under Kubernetes

➜  ~ kubectl get svc -n blockchain
NAME                      TYPE           CLUSTER-IP       EXTERNAL-IP                                                               PORT(S)                           AGE
blockchain-orderer        NodePort       100.68.98.142    <none>                                                                    31010:31010/TCP                   7d4h
blockchain-orderer2       NodePort       100.64.169.137   <none>                                                                    32010:32010/TCP                   7d4h
blockchain-orderer3       NodePort       100.68.185.88    <none>                                                                    31012:31012/TCP                   7d4h
blockchain-org1-ca        NodePort       100.66.249.91    <none>                                                                    30054:30054/TCP                   7d4h
blockchain-org1peer1      NodePort       100.70.28.4      <none>                                                                    30110:30110/TCP,30111:30111/TCP   7d4h
blockchain-org2-ca        NodePort       100.68.243.9     <none>                                                                    30055:30055/TCP                   7d4h
blockchain-org2peer1      NodePort       100.71.114.216   <none>                                                                    30210:30210/TCP,30211:30211/TCP   7d4h
blockchain-org3-ca        NodePort       100.64.199.106   <none>                                                                    30056:30056/TCP                   7d4h
blockchain-org3peer1      NodePort       100.66.55.254    <none>                                                                    30310:30310/TCP,30311:30311/TCP   7d4h
blockchain-org4-ca        NodePort       100.70.219.197   <none>                                                                    30057:30057/TCP                   7d4h
blockchain-org4peer1      NodePort       100.69.141.45    <none>                                                                    30410:30410/TCP,30411:30411/TCP   7d4h
docker                    ClusterIP      100.67.69.23     <none>                                                                    2375/TCP                          7d4h

What I want is to connect Blockchain remotly from a Go app, and send data to write.

Nevertheless, I don't know how to test connectivity, from what I understand, with a NodePort service, I would be able to connect blockchain statically, via ip:port, as states the docs

Exposes the Service on each Node’s IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You’ll be able to contact the NodePort Service, from outside the cluster, by requesting <NodeIP>:<NodePort>

My nodes are hosted on AWS.

Pods I must connect are:

blockchain-org1peer1
blockchain-org1peer2
blockchain-org1peer3

How should I do to be able to connect

-- Juliatzin
hyperledger-fabric
kubernetes

1 Answer

10/7/2019

There are multiple solutions I can think of, and others probably have more ideas.

1) Use a load balancer. You can setup a load balancer, or configure an existing one to forward a port to the nodeport of all the worker nodes in your k8s cluster. Then you can call the backend through that load balancer.

2) Use an ingress. The ingress probably already has a load balancer in front of it, and this might be easier to implement. With an ingress, you don't need a NodePort. You can directly connect the pods from the ingress, or add a service in front of each and connect to that service.

You have multiple pods in the backend, and they seem to be peer nodes in the blockchain, not replicas of the same pod. If you need to create three separate endpoints so you can control which peer you connect, an ingress with three proxies connected to these pods would work.

If you do not care which peer you connect, then you can add a service in front of the three pods as a load balancer. You can add a common label to all three peers, and have your service select its destination using that label, so when you hit the service, it acts as a load balancer between the peers. Then you can expose that service via the ingress.

-- Burak Serdar
Source: StackOverflow