Bitcoin on Kubernetes
Short one. In the first article in this series I've mentioned that I will write an article how to run Bitcoin core node Kubernetes and I never did.
So #1 make sure you have disk space and performant server. At least of 16gb ram and 4cpu cores and at least with 1TB disk space. The faster the better performance it will be as Bitcoin is disk intensive.
Why to do it?
Easier networking
Its easier to network in Kubernetes (for me atleast) an integrate various services and dispose of them when they are not needed. Also there are quite few memes and horror stories that state otherwise, but so far my experience was good with it.
Config management
Pass configs straight to the manifest and call it a day. Just make sure to use stateful set instead of a deployment. I've used mistakenly deployment and it messed up bitcoin node sync needed to resync.
YAML
!! The manifest isn't suited for production use !!
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: bitcoin-core
labels:
app: bitcoin-core
spec:
serviceName: bitcoin-core
replicas: 1
selector:
matchLabels:
app: bitcoin-core
template:
metadata:
labels:
app: bitcoin-core
spec:
containers:
- name: bitcoin-core
image: ruimarinho/bitcoin-core:latest #would be a good idea to fix to a specific version
ports:
- containerPort: 8332
- containerPort: 8333
args: [ "-txindex=1","-rpcthreads=16" ,"-rpcworkqueue=128", "-maxconnections=400","-rpcallowip=0.0.0.0/0","-rpcauth=<username>:<passwhash>","-rpcbind=0.0.0.0", "-dbcache=4000"] # args based on your VM spec.
volumeMounts:
- mountPath: /home/bitcoin/.bitcoin #adjust dir if needed.
name: bitcoin-data
volumes:
- name: bitcoin-data
hostPath:
path: /mnt/bitcoin
type: DirectoryOrCreate
Write to HostPath
I am writing straight to the HostPath which writes directly. If anything goes wrong - node can always be re-synced. I am running single node Kubernetes so I don't care about PVs and PVCs in this case.
Conclusion
With stateful set I run bitcoin node in Kubernetes. So far so good. FYI core node is run on bare metal.