Deploy a Hyperledger Fabric project multi-channel, multi-organization, and multi-cloud on Kubernetes in under 10 minutes

Diego Barahona
May 30, 2019 · 8 min read

Have you tried to deploy a Hyperledger Fabric project to the cloud before? I did, it is not an easy task. This blog post assumes you are already familiar with Hyperledger Fabric’s terminology.

If you want to go for the DIY path and set up everything by your own, you'll end up spending weeks, if not months, trying to figure out how to do it properly, taking care of all the small aspects of what it means to deploy a Fabric network. And even when you finally come out with a good network, you have to start thinking about how are new members going to be added and managed to this consortium. Multi-cloud, scalability, monitoring, recovery, etc.

There's another option which you might have heard about already. Blockchain as a Service (or BaaS). This might seems convenient if you want to avoid all the hustle of becoming an expert in Fabric’s infrastructure just to install the network and deploy your system. But it has a trade-off, a really important trade-off.

If you are creating a blockchain project it means that you care about decentralization and keep your data out of third-party hands so you can make ensure its integrity. Well, with BaaS you are giving away all your control over convenience, and most of the services right now demand the rest of the network to be present in the same BaaS offering, basically centralizing a service that is supposed to be decentralized by nature.

How can you deploy a Hyperledger Fabric solution then, without voiding the benefits of blockchain and still be able to do it quickly?

You basically need a platform as easy as BaaS that let you start in minutes without being an expert, but you don't want to sacrifice on control and security. Forma, a service by WorldSibu (the same company behind Convector), does exactly that.

It creates and orchestrates a whole blockchain network whereas the computing components reside on each of Kubernetes clusters of the network, it doesn't matter if it's in Amazon Web Services (AWS), Google Cloud Platform (GCP), IBM Cloud, Microsoft Azure, or even your own bare-metal cluster, without the platform owning the infrastructure.

Image for post
Image for post

Forma decouples the computing and the blockchain layer. So it’s easy as a BaaS but you never get locked into a single cloud provider.

So you can always choose where you want your infrastructure to run, in a public cloud provider or in your own private infrastructure.

Plus, you always get to decide if you want to leave one cloud provider for another one. As you are never locked to one.

And more importantly, you can access each component as low level as you wish, allowing you to implement interoperability protocols if you need them.


The Project

Image for post
Image for post
Transaction flow diagram: 1) The hospital registers a prescription 2) The insurance company pay the claim 3) Blockchain notifies the dispensary 4) and it updates the prescription status

Since this post is about how to deploy the application, you can clone the repo here. If you feel curious about the implementation logic with Convector behind the example, you can watch the CDOH #5 (Convector Developer Office Hours).

That code showcases some neat features from Hyperledger Fabric:

  • Smart contract events (notify the outside world of some transaction that happened in the blockchain so that something -applications, IoT- can react to them).
  • Multi-channel queries.
  • Convector Models and controllers.
  • Native Fabric SDK usage.

The scenario is pretty simple. Let's assume we need to design an insurance traceability network for the health industry.

  • Multiple hospitals need to register medical prescriptions for their patients.
  • The insurance companies have to pay for those prescriptions.
  • This will have to send a notification back to the hospital when the insurance company fulfilled the payment, so they can update the prescription status.

Notice, the example focuses on demonstrating the blockchain capabilities. The business logic of the example is by no means accurate and should be used only as an example.

In the example scenario, we will have two different channels. In Fabric, a channel is basically the ledger itself, so having two channels is actually having two blockchains in the consortium, which might be composed of different participants (organizations) from each other.

The reason why we would have two different channels is that the members of each channel might be different (data confidentiality and security). While a lot of organizations might be interested in joining the Financial channel, not all of them ought to belong to the Health channel.

The first thing we'll need is to create an account in Forma.

There’s a 7-day free trial for you to test it out! Request it here.

Next, we will need at least one Kubernetse cluster to run the blockchain infrastructure. You can create a free trial in one of the major cloud provider (I prefer Google Cloud Platform, it offers $300 in credits and it's really simple) and follow this guide on how to set up your GCP Cluster (or any other cluster).

For the simplicity of this short example, I'll let WorldSibu host the cluster for me, since it's the easiest way to run a quick test. This is really convenient when you need to run tests on an environment as close to production as possible.

Image for post
Image for post
Forma home page

Click on Create new and you will be prompted for the network name, the location of your cluster, and who do you want to be in the network. Each of the members you add can provide their own cluster as well. Or if you're on a hurry and you want to test something real quick, set up a Ghost Organization (a fake organization under your control)

Image for post
Image for post
What do you need to create? Pick up the name and blockchain technology. Forma supports Hyperledger Fabric at the moment. More technologies in the roadmap.
Image for post
Image for post
Where you will host the blockchain. You have 3 options 1) Managed, 2) Everything hosted by you, 3) Each member host on different machines.
Image for post
Image for post
Who do you want in the network? Or a ghost name for a fake organization under your control.

When you create a network with multiple participants, every participant needs to accept the modifications to the network before proceeding.

Click Deploy and go drink a cup of coffee ☕️. Forma will start to create the connections between you and the rest of the clusters in the network, start up all the necessary containers for the blockchain, and configure it automatically for you.

Once you're back, your blockchain should be ready to install some channels or smart contracts, which actually is our next step.

Let's create two new channels, one named Financial and another one called Health.

Image for post
Image for post
Only one ledger (channel) is created by default, Public, including all the members of the network.
Image for post
Image for post
Create the Financial ledger and include the organizations you need.
Image for post
Image for post
Create the Health ledger and include the organizations you need.

Back to the code, make sure you use Node 8.x (if you are in a higher version you can always use NVM) and run npm install .

When that task is done, run npm run cc:package -- financial org1 and npm run cc:package -- health org1 . This is to build the Typescript code to Javascript, that’s what we're going to install.

You'll notice there're two new folders in the project's root: chaincode-financial and chaincode-health, let's zip the content and upload them to Forma. Zip the folders content but not the folder itself, or using a command like cd chaincode-financial && zip -r ../financial.zip . && cd ..

Image for post
Image for post

Go to the Financial channel and install the financial.zip generated in the previews step.

Image for post
Image for post
Image for post
Image for post
Forma supports both NodeJs and Golang chaincodes. It also supports private data collections very simple.

Click on deploy and you're done. Now let's repeat the install steps with the health.zip chaincode but this time in the Health channel.

Now, we’ll need the connection information to the blockchain network, this will allow you to connect to it from the outside. For this we'll need a service account, creating one with Forma is really easy. Go to the network details (Your nodes environment and identities) and you'll find your environment details right there.

Image for post
Image for post
Image for post
Image for post
Provide the username and password, as well as any attributes for RBAC authentication.
Image for post
Image for post
Download the configuration for a certain project.

Create the account and download the connection profile, this file describes the whole network topology. It’s used for you to connect with the blockchain through any of Fabric SDKs or through Convector.

We just have one extra step left, we just registered the account, but before we're able to use it, we need to enroll it with the CA to get a certificate.

Clone this repo which will help you with that https://github.com/worldsibu/fabric-helpers and follow the instructions in the README, it's basically copying the network profile and provide your user/password to enroll the account.

Copy the connection profile and the generated keys from the step above to the ./config folder and run npm run lerna:test:e2e to run the tests with the new infrastructure.

Now, we need to make sure the events are working as expected. Open two terminal windows and run npm run listener to start a server listening to events in the blockchain, and then npm run transaction to send a transaction and emit an event from the chaincode.

Image for post
Image for post

Making blockchain applications now becomes really straight forward, as you can focus your time in designing and on-boarding the network members, and better describe the business logic. Also with an open source framework like Convector that makes it easy to create logic and test it locally, and with platforms like Forma, you can deploy those projects to real life infrastructure to run a stress test and measure your performance.

If you want to learn more about Convector, check out its documentation or the posts right here on medium.
If you are interested in learn more about Forma, checkout the getting start page, or sign up today for a free trial.

HackerNoon.com

#BlackLivesMatter

By HackerNoon.com

how hackers start their afternoon. the real shit is on hackernoon.com. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Thanks to Walter Montes

Diego Barahona

Written by

DevOps and Blockchain Architect and Consultant

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Diego Barahona

Written by

DevOps and Blockchain Architect and Consultant

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store