How to deploy a Blockchain with 7 nodes using Smilo network on Kubernetes in 5 minutes
Smilo Architecture:
It comprises of several components, the go-smilo client and the Blackbox Transaction Manager, if you would like to understand more please check the following link Smilo v1.9.2.2 — Smilodon Populator — Autonomous community (GETH 1.9.2) or check our Wiki
1. Go-smilo Node (Modified GETH client)
It is designed to be a lightweight blockchain that takes advantage of the R&D and battle-tested Ethereum GETH 1.9.x PoW Blockchain. It is updated regularly such that it is in line with the future GETH releases.
Some of the modifications (not all) done to the Smilo node are:
- Support for 5 consensus algorithms SPoRT, SPoRT DAO, Istanbul DAO, Clique, PoW
- The P2P layer is modified to allow connections to/from specific pre-set nodes. When using SPoRT DAO or Istanbul DAO, this can be modified only via smart contracts.
- The block generation logic has been modified to have two states: `public state root` and `private state root`. Private transactions do not allow the transfer of tokens, transfer of tokens privately should be done via ZK Snarks public smart contracts.
- Block validation logic changed to handle `private transactions`
- The dual token system introduced. XSM (Smilo) and XSP (SmiloPay). Users pay for transactions with XSP and Gas deposit. The gas deposit is returned if all goes well.
- The TX Pool layer is modified to restrict certain addresses to have transactions submitted to blocks. This feature allows the Consensus Miners to reject transactions created by particular addresses, eg: A consortium using Smilo Enterprise can blacklist accounts, in order to temporarily/permanently freeze stolen funds. This useful feature can also be used to stop DDOS attacks given the addresses can be identified and blocked temporarily/permanently by the Consensus Miners.
Overview of Smilo Architecture
Introduction to Kubernetes
Kubernetes is a container orchestration system that manages containers at scale. Initially developed by Google based on its experience running containers in production, Kubernetes is open source and actively developed by a community around the world.
Goal
Create a production ready cluster for a Consortium Blockchain for the ABCD quartet of grain traders Consortium using Smilo Blockchain Network and Blackbox Transaction Manager.
- Kubernetes Master node
The master node (a node in Kubernetes refers to a server) is responsible for managing the state of the cluster. It runs Etcd, which stores cluster data among components that schedule workloads to worker nodes.
- Kubernetes Worker node
Worker nodes are the servers where your workloads (i.e. containerized applications and services) will run. A worker will continue to run your workload once they’re assigned to it, even if the master goes down once scheduling is complete. A cluster’s capacity can be increased by adding workers.
You should have a cluster ready to run containerized applications, provided that the servers in the cluster have sufficient CPU and RAM resources for your applications to consume. The cluster itself will consume around 300–500MB of memory and 10% of CPU on each node.
Prerequisites
- 2 servers running Ubuntu 18.04, the Master node should have at least 2GB RAM and 1 vCPUs and the Worker node should have at least 32GB RAM and 7vCPUs. You should be able to SSH into each server as the root user with your SSH key pair.
- Ruby 2.6.3 and colorize installed on all servers:
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.6.3
gem install colorize
Step 1 — Setting Up K3S
K3S is the Lightweight Kubernetes by Rancher labs, check k3s.io
Install k3s on Master node
curl -sfL https://get.k3s.io | sh -
Configure namespace
export YOUR_NAMESPACE="smilo-test"
kubectl config set-context $(kubectl config current-context) --namespace=$YOUR_NAMESPACE
Get token
cat /var/lib/rancher/k3s/server/node-token
Export the token to env var NODE_TOKEN
export NODE_TOKEN="node-token cat output here"
Install agent on Worker node
curl -sfL https://get.k3s.io | K3S_URL=https://$KUBERNETES_MASTER:6443 K3S_TOKEN=$NODE_TOKEN sh -
Restart / status
sudo service k3s status
sudo service k3s restart
Step 2 — Prepare Kubernetes Cluster
Clone Kubernetes Smilo Github project
git clone https://github.com/smilofoundation/kubernetes-smilo.git
Create symlinks
ln -s 7nodes/smilobft-7nodes-blackbox/kubernetes-smilo-smilobft-7nodes.yaml kubernetes-smilo.yaml
ln -s 7nodes/nodes-7.yaml nodes.yaml
Generate new keys with smilo-keygen command (It will generate keys for Smilo & Blackbox)
./smilo-keygen
Or Generate new keys via init script (It will generate keys for Smilo & Blackbox)
- un-comment smilo-init section (line 25 onwards):
#
# `
# puts ""
# puts " Generating keys..."
# `
# # generate the keygen script
# # to generate nodekey, account keys, and
# # smilo transaction manger (tm.pub,tm.key) keys.
# ./smilo-keygen
# `
Execute the smilo-init command
./smilo-init
Step 3 — Deploy Smilo Blockchain to Kubernetes with a single command:
This command start a Kubernetes deployment on your cluster, it will deploy 7 Smilo Blockchain Docker Nodes with a single command.
kubectl apply -f 7nodes/smilobft-7nodes-blackbox/k8s-yaml/
That’s all folks, you already have it all installed and the cluster will start a blockchain from block zero without any further customization’s.
You can now check the deployment status with the Get pods command.
Get pods
watch "k3s kubectl get pods"
kubectl get pods --all-namespaces
Describe pod
kubectl describe pod
That’s all you need to have your Smilo Kubernetes Private Blockchain with Private smart contracts operational on the cloud of your preference, follow the next sections to learn more about the most common operations of a Smilo Blockain DevOps.
Bonus section:
1 — How to SSH into node and run basic GETH commands ?
Get block number
watch "geth --exec eth.blockNumber attach ipc:/etc/smilo/sdata/dd/geth.ipc"
geth --exec eth.blockNumber attach ipc:/etc/smilo/sdata/dd/geth.ipc
Get balance
watch "geth --exec 'eth.getBalance(eth.accounts[0])'" attach ipc:/etc/smilo/sdata/dd/geth.ipc
Get SmiloPay
watch "geth --exec 'eth.getSmiloPay(eth.accounts[0])'" attach ipc:/etc/smilo/sdata/dd/geth.ipc
Show connected peers
watch "geth --exec admin.peers attach ipc:/etc/smilo/sdata/dd/geth.ipc"
How to Attach to console
geth attach /etc/smilo/sdata/dd/geth.ipc
2 — Blackbox devops:
SSH into node1
POD_NAME=$(kubectl get pods | grep node1 | awk '{print $1}')
kubectl exec -it $POD_NAME -c smilo /bin/ash
Check if node is online
rm -rf upcheck && wget http://localhost:9001/upcheck && cat upcheck
rm -rf upcheck && wget http://10.42.1.204:9001/upcheck && cat upcheck
Check for config files
cat /etc/smilo/sdata/tm/blackbox-config-with-hosts.json
Run a Private Smart Contract
cd /etc/smilo/sdata/contracts
./runscript.sh private_contract.js
Run a Public Smart Contract
cd /etc/smilo/sdata/contracts
./runscript.sh public_contract.js