Setting up the Hyperledger Sawtooth Development Environment with Kubernetes

0
1385

This article is aimed at open source enthusiasts with an interest in blockchain technologies and who have working knowledge of the Hyperledger Sawtooth project.

In this article, we will create a single Hyperledger Sawtooth validator node with Kubernetes.

The environment required for this uses Minikube to deploy Sawtooth as a containerised application in a local Kubernetes cluster inside a virtual machine (VM) on your computer. After completing this procedure, you will have the environment required for evaluating a Hyperledger Sawtooth network or use the Sawtooth SDKs. This article assumes you are familiar with Kubernetes and are setting up the single-node Minikube.

Prerequisites

This application development environment requires kubectl and Minikube with a supported VM hypervisor, such as VirtualBox, HyperV, etc.

The application development environment

This application development environment is a single validator node that is running a validator, a REST API, and three transaction processors. This environment uses dev mode consensus and parallel transaction processing.

The Kubernetes cluster has one pod with a container for each Sawtooth component. After the container begins to run, you can use the Kubernetes dashboard to view the pod status, the container names, Sawtooth log files, and more.

This example environment includes the following transaction processors:

  • Settings handles Sawtooth’s on-chain settings. The sawtooth-settings-tp transaction processor is required for this environment.
  • IntegerKey is a basic application (also called a transaction family) that introduces Sawtooth functionality. The sawtooth-intkey-tp-python transaction processor works with the int-key client, which has shell commands to perform integer-based transactions.
  • XO is a simple application for playing a game of tic-tac-toe on the blockchain. The sawtooth-xo-tp-python transaction processor works with the xo client, which has shell commands to define players and play a game. XO will be described in a later tutorial.

Downloading the Sawtooth configuration file

Download the Kubernetes configuration file for a single-node environment from https://sawtooth.hyperledger.org/docs/core/nightly/master/app_developers_guide/sawtooth-kubernetes-default.yaml.

The sawtooth-kubernetes-default.yaml file defines the process for constructing a one-node Sawtooth environment with the following containers:

  • A single validator using dev mode consensus
  • A REST API connected to the validator
  • The Settings transaction processor (sawtooth-settings)
  • The IntegerKey transaction processor (intkey-tp-python)
  • The XO transaction processor (xo-tp-python)
  • A shell container for running Sawtooth commands (a command line client)

The configuration file also specifies the container images to download (from DockerHub) and the network settings needed for the containers to communicate correctly.

Figure 1: Sawtooth Kubernetes deployment architecture

Starting the Sawtooth cluster

Use the following steps to start the Sawtooth network, and change your working directory to the same one in which you saved the configuration file. Make sure that Minikube is running.

$ minikube status

minikube: Running

cluster: Running

kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100

Minikube start

Start Sawtooth in a local Kubernetes cluster, as follows:

$ kubectl apply -f sawtooth-kubernetes-default.yaml

Optionally, start the Minikube dashboard using the following command:

$ minikube dashboard

This command opens the dashboard in your default browser. The overview page shows the Sawtooth deployment (sawtooth-0) and pod (sawtooth-0-POD-ID).

To test basic Sawtooth functionality, connect to the shell container using the command below:

$ kubectl exec -it $(kubectl get pods | awk ‘/sawtooth-0/{print $1}’) --container sawtooth-shell -- bash

To display the list of blocks on the Sawtooth blockchain, use the command given below:

root@sawtooth-0# sawtooth block list

Because this is a new blockchain, there is only one block. Block 0 is the genesis block. The output is similar to the example shown below:

NUM BLOCK_ID BATS TXNS SIGNER

020d7b66577217 58d1ad1a3392daadd57473 d84e1e1c8c58c14ec8 62ff7fbf44a3bef4d82c 40052dd8fc2808191f83 0447df59fe074aea02a000ff64bc458e256 1 1 025f80...

Copy the block ID from the previous output, and then use the following command to display more information about the block.

root@sawtooth-0# sawtooth block show {BLOCK-ID}

The output of this command is quite long, because it includes all data stored under that block.

batches:

- header:

signer_public_key: 03f257dee6f021b579 cb59d34f2489603892 d44bb2e181eaa444e1bb4f4b4b812d

transaction_ids:

-

3f6c2f60a66317 f09d052757dba605d 0c1c56caa38cdfdefb d7f45 11a830a1fc22d8e 13ff86201ac309344 605b5df77a85e5979 9c16c 3ba9e3cba950b709be04

header_signature:

6e5446e99bae1fe2d7d4a7561880bd069cc 404e099dd4380a 7f491dd0588584b0b6b558d636eb42720d6c 839c6755182d30 04b905429088413df00f82ec0fd1e

...

At this point, your environment is ready for experimenting with Sawtooth. The rest of this section introduces you to Sawtooth functionality.

Verifying the Sawtooth components

To check whether a Sawtooth component is running, connect to the component’s container and run the ps command.

Use the kubectl exec command from your computer to connect to a Sawtooth container. On the Kubernetes dashboard, the Pods page displays the container names. For example, connect to the validator container with the following command:

$ kubectl exec -it $(kubectl get pods | awk ‘/sawtooth-0/{print $1}’) --container sawtooth-validator -- bash

After connecting to the container, you can use ps to verify that the Sawtooth component is running.

root@sawtooth-0# ps -A fw

In the sawtooth-validator container, the output resembles the following example:

PID TTY STAT TIME COMMAND

77 pts/0Ss 0:00 bash

96 pts/0R+ 0:00 \_ ps -A fw

1 ?Ss 0:00 bash -c sawadm keygen && if [ ! -e config-genesis.batch ]; then sawset genesis -k /etc/sawtooth/keys/vali

27 ?Sl 0:17 /usr/bin/python3 /usr/bin/sawtooth-validator -vv --endpoint tcp://10.96.15.213:8800 --bind component:tcp:

Examining Sawtooth logs

The Sawtooth log files are available on the Kubernetes dashboard.

  • From the dashboard’s overview page, click on the Sawtooth pod name.
  • On the Sawtooth pod page, click on the Logs button.
  • On the Logs page, select the Sawtooth component. For example, to view the validator log messages, select sawtooth-validator.

Stop the Sawtooth Kubernetes cluster

Use the following commands to stop and reset the Sawtooth environment:

  • Log out of all Sawtooth containers.
  • Stop Sawtooth and delete the pod. Run the following command from the same directory in which you saved the configuration file.
$ kubectl delete -f sawtooth-kubernetes-default.yaml

deployment.extensions “sawtooth-0” deleted

service “sawtooth-0” deleted

LEAVE A REPLY

Please enter your comment!
Please enter your name here