Blockchain is a continuously growing list of records, called blocks, which are linked and secured using cryptography. The blockchain is a public ledger that records bitcoin transactions. In this blog, we will show you how to deploy and run BitCoin Core in Kubernetes. We will be using Azure Container Service (AKS), Microsoft’s managed Kubernetes service but same concepts should apply to other cloud providers or local Kubernetes deployments as well.
BitCoin Core in Kubernetes
Clone our github repo to fetch Kubernetes configuration files and list them:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ git clone https://github.com/coderiseio/bitcoin-core-kubernetes.git && cd azure/
MacBook-Pro:bitcoin-core coderiseio$ ls
bitcoin-core-pvc.yaml bitcoin-core.yaml
[/bash]
[bash]
MacBook-Pro:bitcoin-core coderiseio$ cat bitcoin-core-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: bitcoin-core-pv-claim
spec:
storageClassName: default
accessModes:
– ReadWriteOnce
resources:
requests:
storage: 150Gi
[/bash]
[bash]
MacBook-Pro:bitcoin-core coderiseio$ cat bitcoin-core.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: bitcoin-core-deployment labels: app: bitcoin-core-app tier: bitcoin spec: replicas: 1 template: metadata: labels: app: bitcoin-core-app tier: bitcoin spec: volumes: - name: bitcoin-core-pv-storage persistentVolumeClaim: claimName: bitcoin-core-pv-claim containers: - name: bitcoin-core image: "ruimarinho/bitcoin-core:latest" imagePullPolicy: IfNotPresent volumeMounts: - name: bitcoin-core-pv-storage mountPath: "/home/bitcoin/.bitcoin" --- apiVersion: v1 kind: Service metadata: name: bitcoin-core-service labels: tier: bitcoin spec: selector: app: bitcoin-core-app tier: bitcoin ports: - port: 80 targetPort: 8332 protocol: TCP name: bitcoin-core-port
[/bash]
Create a new Persistent Volume Claim(PVC) for data storage:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl create -f bitcoin-core-pvc.yaml
persistentvolumeclaim “bitcoin-core-pv-claim” created
[/bash]
Confirm PVC bound was successful:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
bitcoin-core-pv-claim Bound pvc-58bb6fb8-xxxx-xxxx-xxxx-0a58by1f0648 150Gi RWO default 1m
[/bash]
Create Kubernetes service and deployment for BitCoin Core:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl create -f bitcoin-core.yaml
deployment “bitcoin-core-deployment” created
service “bitcoin-core-service” created
[/bash]
Confirm Service was successful:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
bitcoin-core-service ClusterIP 10.0.xxx.xxx <none> 80/TCP 31s
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 6d
[/bash]
Confirm Deployment was successful:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
bitcoin-core-deployment 1 1 1 0 41s
[/bash]
Check Pod status:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl get pods -o wide | grep bitcoin
bitcoin-core-deployment-205-cwchl 1/1 Running 0 2m 10.244.0.7 aks-nodepool1-83642819-1
[/bash]
Optionally, you can describe the Pod:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl describe pod bitcoin-core-deployment-xxxx-cwchl
[/bash]
Exec into the BitCoin Pod:
[bash]
MacBook-Pro:bitcoin-core coderiseio$ kubectl exec -it bitcoin-core-deployment-205-cwchl bash
root@bitcoin-core-deployment-205-cwchl:/#
[/bash]
Switch to ‘bitcoin’ user and list contents of BITCOIN_DATA directory which will show you the data.
[bash]
root@bitcoin-core-deployment-205-cwchl:/# gosu bitcoin bash
bitcoin@bitcoin-core-deployment-205-cwchl:/$ ls -ltr /home/bitcoin/.bitcoin/
total 26324
drwx—— 2 bitcoin root 16384 Jan 10 06:24 lost+found
-rw——- 1 bitcoin bitcoin 2 Jan 10 06:24 bitcoind.pid
-rw——- 1 bitcoin bitcoin 0 Jan 10 06:24 db.log
drwx—— 2 bitcoin bitcoin 4096 Jan 10 06:24 chainstate
drwx—— 2 bitcoin bitcoin 4096 Jan 10 06:24 database
-rw——- 1 bitcoin bitcoin 4178 Jan 10 06:24 peers.dat
-rw——- 1 bitcoin bitcoin 37 Jan 10 06:24 banlist.dat
-rw——- 1 bitcoin bitcoin 1384448 Jan 10 06:25 wallet.dat
drwx—— 3 bitcoin bitcoin 4096 Jan 10 06:26 blocks
-rw——- 1 bitcoin bitcoin 25523880 Jan 10 06:31 debug.log
bitcoin@bitcoin-core-deployment-205-cwchl:/$
[/bash]
To confirm bitcoin daemon is responding, you can execute this query using bitcoin-cli
[bash]
bitcoin@bitcoin-core-deployment-205-cwchl:/$ bitcoin-cli getmininginfo
{
“blocks”: 127xx1,
“currentblockweight”: 0,
“currentblocktx”: 0,
“difficulty”: 434877.04xxxx6276,
“errors”: “”,
“networkhashps”: 39850xxx.484,
“pooledtx”: 0,
“chain”: “main”
}
[/bash]
This should confirm that you have successfully deployed the BitCoin Core in Kubernetes.
Please note that this should only be used for experimental purpose and is not production ready as we have not covered authentication, exposing the service publicly, creating configuration file and related topics. You can post comments and let us know if you are interested and we will try to cover them in future blogs. Until then, stay tuned and don’t forget to read our other blogs here.
Reference:
For this blog, we have referenced the docker image published and maintained by ‘ruimarinho’ here.