Getting Started with Helm Charts (ScalarDL Ledger / Ledger only)
This document explains how to get started with ScalarDL Ledger using Helm Chart on a Kubernetes cluster as a test environment. Here, we assume that you already have a Mac or Linux environment for testing. We use Minikube in this document, but the steps we will show should work in any Kubernetes cluster.
Requirement
You need to subscribe to ScalarDL Ledger in the AWS Marketplace or Azure Marketplace to get the following container images.
- AWS Marketplace
- scalar-ledger
- scalar-ledger-envoy
- scalardl-schema-loader-ledger
- Azure Marketplace
- scalar-ledger
- scalardl-envoy
- scalardl-schema-loader
Please refer to the following documents for more details.
- How to install Scalar products through AWS Marketplace
- How to install Scalar products through Azure Marketplace
What we create
We will deploy the following components on a Kubernetes cluster as follows.
+--------------------------------------------------------------------------------------------------------------------------------------+
| [Kubernetes Cluster] |
| |
| [Pod] [Pod] [Pod] [Pod] |
| |
| +-------+ +-----------------+ |
| +---> | Envoy | ---+ +---> | ScalarDL Ledger | ---+ |
| | +-------+ | | +-----------------+ | |
| | | | | |
| +--------+ +---------+ | +-------+ | +-------------------+ | +-----------------+ | +------------+ |
| | Client | ---> | Service | ---+---> | Envoy | ---+---> | Service | ---+---> | ScalarDL Ledger | ---+---> | PostgreSQL | |
| +--------+ | (Envoy) | | +-------+ | | (ScalarDL Ledger) | | +-----------------+ | +------------+ |
| +---------+ | | +-------------------+ | | |
| | +-------+ | | +-----------------+ | |
| +---> | Envoy | ---+ +---> | ScalarDL Ledger | ---+ |
| +-------+ +-----------------+ |
| |
+--------------------------------------------------------------------------------------------------------------------------------------+
Step 1. Start a Kubernetes cluster
First, you need to prepare a Kubernetes cluster. If you use a minikube environment, please refer to the Getting Started with Scalar Helm Charts. If you have already started a Kubernetes cluster, you can skip this step.
Step 2. Start a PostgreSQL container
ScalarDL Ledger uses some kind of database system as a backend database. In this document, we use PostgreSQL.
You can deploy PostgreSQL on the Kubernetes cluster as follows.
-
Add the Bitnami helm repository.
helm repo add bitnami https://charts.bitnami.com/bitnami
-
Deploy PostgreSQL.
helm install postgresql-ledger bitnami/postgresql \
--set auth.postgresPassword=postgres \
--set primary.persistence.enabled=false -
Check if the PostgreSQL container is running.
kubectl get pod
[Command execution result]
NAME READY STATUS RESTARTS AGE
postgresql-ledger-0 1/1 Running 0 11s
Step 3. Create a working directory
We will create some configuration files and key/certificate files locally. So, create a working directory for them.
- Create a working directory.
mkdir -p ~/scalardl-test/certs/
Step 4. Create key/certificate files
Note: In this guide, we will use self-sign certificates for the test. However, it is strongly recommended that these certificates NOT be used in production.
-
Change the working directory to
~/scalardl-test/certs/
directory.cd ~/scalardl-test/certs/
-
Create a JSON file that includes Ledger information.
cat << 'EOF' > ~/scalardl-test/certs/ledger.json
{
"CN": "ledger",
"hosts": ["example.com","*.example.com"],
"key": {
"algo": "ecdsa",
"size": 256
},
"names": [
{
"O": "ledger",
"OU": "test team",
"L": "Shinjuku",
"ST": "Tokyo",
"C": "JP"
}
]
}
EOF -
Create a JSON file that includes Client information.
cat << 'EOF' > ~/scalardl-test/certs/client.json
{
"CN": "client",
"hosts": ["example.com","*.example.com"],
"key": {
"algo": "ecdsa",
"size": 256
},
"names": [
{
"O": "client",
"OU": "test team",
"L": "Shinjuku",
"ST": "Tokyo",
"C": "JP"
}
]
}
EOF -
Create key/certificate files for the Ledger.
cfssl selfsign "" ./ledger.json | cfssljson -bare ledger
-
Create key/certificate files for the Client.
cfssl selfsign "" ./client.json | cfssljson -bare client
-
Confirm key/certificate files are created.
ls -1
[Command execution result]
client-key.pem
client.csr
client.json
client.pem
ledger-key.pem
ledger.csr
ledger.json
ledger.pem
Step 5. Create DB schemas for ScalarDL Ledger using Helm Charts
We will deploy a ScalarDL Schema Loader on the Kubernetes cluster using Helm Charts.
The ScalarDL Schema Loader will create the DB schemas for ScalarDL Ledger in PostgreSQL.
-
Change the working directory to
~/scalardl-test/
.cd ~/scalardl-test/
-
Add the Scalar helm repository.
helm repo add scalar-labs https://scalar-labs.github.io/helm-charts
-
Create a secret resource to pull the ScalarDL container images from AWS/Azure Marketplace.
- AWS Marketplace
kubectl create secret docker-registry reg-ecr-mp-secrets \
--docker-server=709825985650.dkr.ecr.us-east-1.amazonaws.com \
--docker-username=AWS \
--docker-password=$(aws ecr get-login-password --region us-east-1) - Azure Marketplace
kubectl create secret docker-registry reg-acr-secrets \
--docker-server=<your private container registry login server> \
--docker-username=<Service principal ID> \
--docker-password=<Service principal password>
Please refer to the following documents for more details.
- AWS Marketplace
-
Create a custom values file for ScalarDL Schema Loader (schema-loader-ledger-custom-values.yaml).
-
AWS Marketplace
cat << 'EOF' > ~/scalardl-test/schema-loader-ledger-custom-values.yaml
schemaLoading:
schemaType: "ledger"
image:
repository: "709825985650.dkr.ecr.us-east-1.amazonaws.com/scalar/scalardl-schema-loader-ledger"
version: "3.6.0"
imagePullSecrets:
- name: "reg-ecr-mp-secrets"
databaseProperties: |
scalar.db.contact_points=jdbc:postgresql://postgresql-ledger.default.svc.cluster.local:5432/postgres
scalar.db.username={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_USERNAME "" }}
scalar.db.password={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_PASSWORD "" }}
scalar.db.storage=jdbc
secretName: "ledger-credentials-secret"
EOF -
Azure Marketplace
cat << 'EOF' > ~/scalardl-test/schema-loader-ledger-custom-values.yaml
schemaLoading:
schemaType: "ledger"
image:
repository: "<your private container registry>/scalarinc/scalardl-schema-loader"
version: "3.6.0"
imagePullSecrets:
- name: "reg-acr-secrets"
databaseProperties: |
scalar.db.contact_points=jdbc:postgresql://postgresql-ledger.default.svc.cluster.local:5432/postgres
scalar.db.username={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_USERNAME "" }}
scalar.db.password={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_PASSWORD "" }}
scalar.db.storage=jdbc
secretName: "ledger-credentials-secret"
EOF
-
-
Create a secret resource that includes a username and password for PostgreSQL.
kubectl create secret generic ledger-credentials-secret \
--from-literal=SCALAR_DL_LEDGER_POSTGRES_USERNAME=postgres \
--from-literal=SCALAR_DL_LEDGER_POSTGRES_PASSWORD=postgres -
Deploy the ScalarDL Schema Loader.
helm install schema-loader-ledger scalar-labs/schema-loading -f ./schema-loader-ledger-custom-values.yaml
-
Check if the ScalarDL Schema Loader pod is deployed and completed.
kubectl get pod
[Command execution result]
NAME READY STATUS RESTARTS AGE
postgresql-ledger-0 1/1 Running 0 11m
schema-loader-ledger-schema-loading-46rcr 0/1 Completed 0 3sIf the ScalarDL Schema Loader pod is ContainerCreating or Running, wait for the process will be completed (The STATUS will be Completed).
Step 6. Deploy ScalarDL Ledger on the Kubernetes cluster using Helm Charts
-
Create a custom values file for ScalarDL Ledger (scalardl-ledger-custom-values.yaml).
-
AWS Marketplace
cat << 'EOF' > ~/scalardl-test/scalardl-ledger-custom-values.yaml
envoy:
image:
repository: "709825985650.dkr.ecr.us-east-1.amazonaws.com/scalar/scalar-ledger-envoy"
version: "1.3.0"
imagePullSecrets:
- name: "reg-ecr-mp-secrets"
ledger:
image:
repository: "709825985650.dkr.ecr.us-east-1.amazonaws.com/scalar/scalar-ledger"
version: "3.6.0"
imagePullSecrets:
- name: "reg-ecr-mp-secrets"
ledgerProperties: |
scalar.db.contact_points=jdbc:postgresql://postgresql-ledger.default.svc.cluster.local:5432/postgres
scalar.db.username={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_USERNAME "" }}
scalar.db.password={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_PASSWORD "" }}
scalar.db.storage=jdbc
scalar.dl.ledger.proof.enabled=true
scalar.dl.ledger.proof.private_key_path=/keys/private-key
secretName: "ledger-credentials-secret"
extraVolumes:
- name: "ledger-keys"
secret:
secretName: "ledger-keys"
extraVolumeMounts:
- name: "ledger-keys"
mountPath: "/keys"
readOnly: true
EOF -
Azure Marketplace
cat << 'EOF' > ~/scalardl-test/scalardl-ledger-custom-values.yaml
envoy:
image:
repository: "<your private container registry>/scalarinc/scalardl-envoy"
version: "1.3.0"
imagePullSecrets:
- name: "reg-acr-secrets"
ledger:
image:
repository: "<your private container registry>/scalarinc/scalar-ledger"
version: "3.6.0"
imagePullSecrets:
- name: "reg-acr-secrets"
ledgerProperties: |
scalar.db.contact_points=jdbc:postgresql://postgresql-ledger.default.svc.cluster.local:5432/postgres
scalar.db.username={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_USERNAME "" }}
scalar.db.password={{ default .Env.SCALAR_DL_LEDGER_POSTGRES_PASSWORD "" }}
scalar.db.storage=jdbc
scalar.dl.ledger.proof.enabled=true
scalar.dl.ledger.proof.private_key_path=/keys/private-key
secretName: "ledger-credentials-secret"
extraVolumes:
- name: "ledger-keys"
secret:
secretName: "ledger-keys"
extraVolumeMounts:
- name: "ledger-keys"
mountPath: "/keys"
readOnly: true
EOF
-
-
Create secret resource
ledger-keys
.kubectl create secret generic ledger-keys --from-file=private-key=./certs/ledger-key.pem
-
Deploy the ScalarDL Ledger.
helm install scalardl-ledger scalar-labs/scalardl -f ./scalardl-ledger-custom-values.yaml
-
Check if the ScalarDL Ledger pods are deployed.
kubectl get pod
[Command execution result]
NAME READY STATUS RESTARTS AGE
postgresql-ledger-0 1/1 Running 0 14m
scalardl-ledger-envoy-547bbf7546-6cn88 1/1 Running 0 52s
scalardl-ledger-envoy-547bbf7546-rpg5p 1/1 Running 0 52s
scalardl-ledger-envoy-547bbf7546-x2vlg 1/1 Running 0 52s
scalardl-ledger-ledger-9bdf7f8bd-29bzm 1/1 Running 0 52s
scalardl-ledger-ledger-9bdf7f8bd-9fklw 1/1 Running 0 52s
scalardl-ledger-ledger-9bdf7f8bd-9tw5x 1/1 Running 0 52s
schema-loader-ledger-schema-loading-46rcr 0/1 Completed 0 3m38sIf the ScalarDL Ledger pods are deployed properly, you can see the STATUS are Running.
-
Check if the ScalarDL Ledger services are deployed.
kubectl get svc
[Command execution result]
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 47d
postgresql-ledger ClusterIP 10.109.253.150 <none> 5432/TCP 15m
postgresql-ledger-hl ClusterIP None <none> 5432/TCP 15m
scalardl-ledger-envoy ClusterIP 10.106.141.153 <none> 50051/TCP,50052/TCP 83s
scalardl-ledger-envoy-metrics ClusterIP 10.108.36.136 <none> 9001/TCP 83s
scalardl-ledger-headless ClusterIP None <none> 50051/TCP,50053/TCP,50052/TCP 83s
scalardl-ledger-metrics ClusterIP 10.98.4.217 <none> 8080/TCP 83sIf the ScalarDL Ledger services are deployed properly, you can see private IP addresses in the CLUSTER-IP column. (Note:
scalardl-ledger-headless
has no CLUSTER-IP.)
Step 7. Start a Client container
We will use certificate files in a Client container. So, we create a secret resource and mount it to a Client container.
-
Create secret resource
client-keys
.kubectl create secret generic client-keys --from-file=certificate=./certs/client.pem --from-file=private-key=./certs/client-key.pem
-
Start a Client container on the Kubernetes cluster.
cat << 'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: "scalardl-client"
spec:
containers:
- name: scalardl-client
image: eclipse-temurin:8
command: ['sleep']
args: ['inf']
volumeMounts:
- name: "client-keys"
mountPath: "/keys"
readOnly: true
volumes:
- name: "client-keys"
secret:
secretName: "client-keys"
restartPolicy: Never
EOF -
Check if the Client container is running.
kubectl get pod scalardl-client
[Command execution result]
NAME READY STATUS RESTARTS AGE
scalardl-client 1/1 Running 0 11s
Step 8. Run ScalarDL sample contracts in the Client container
The following explains the minimum steps. If you want to know more details about ScalarDL and the contract, please refer to the Getting Started with ScalarDL.
-
Run bash in the Client container.
kubectl exec -it scalardl-client -- bash
After this step, run each command in the Client container.
-
Install the git, curl and unzip commands in the Client container.
apt update && apt install -y git curl unzip
-
Clone ScalarDL Java Client SDK git repository.
git clone https://github.com/scalar-labs/scalardl-java-client-sdk.git
-
Change the directory to
scalardl-java-client-sdk/
.cd scalardl-java-client-sdk/
pwd
[Command execution result]
/scalardl-java-client-sdk -
Change branch to arbitrary version.
git checkout -b v3.6.0 refs/tags/v3.6.0
git branch
[Command execution result]
master
* v3.6.0