Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes configuration for bitcoin and electrumx #3573

Merged
merged 35 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c912a49
Bitcoin node configuration base template
nkuba May 18, 2023
9741c48
Bitcoin node overlay for keep-test
nkuba May 18, 2023
642cb25
Add bitcoind template and keep-test configuration
nkuba May 25, 2023
ccf320e
Merge remote-tracking branch 'origin/main' into bitcoin-kube-config
nkuba May 25, 2023
3512957
Define storageclass for bitcoind node
nkuba May 26, 2023
bd53113
Define service for bitcoind node
nkuba May 26, 2023
1c0e47d
Define common labels for bitcoind node
nkuba May 26, 2023
5e26b53
Remove rpc-host config key for bitcoind
nkuba May 26, 2023
07681cc
Remove duplicated settings from bitcoind statefulset
nkuba May 26, 2023
c6dc412
Run bitcoind with disablewallet and txindex
nkuba May 26, 2023
51dd2c3
Add required storage estimation for bitcoind node
nkuba May 26, 2023
b182549
Use keepnetwork/bitcoind image
nkuba May 26, 2023
40f183c
Define securitycontext for bitcoind statefulset
nkuba May 26, 2023
b78d4db
Define resources request for bitcoind statefulset
nkuba May 26, 2023
c0d5741
Define bitcoin-testnet namespace for keep-test
nkuba May 26, 2023
36188b7
Define bitcoind configuration for keep-test
nkuba May 26, 2023
6528539
Define liveness probe for bitcoind
nkuba May 26, 2023
71076fb
Update expected error message for electrumx server
nkuba May 29, 2023
c5bad30
Use bitcoind v24.1 docker image
nkuba Jun 6, 2023
9029455
Define snapshot class for bitcoin node
nkuba Jun 6, 2023
c72fe40
Run second replica of bitcoind from snapshot
nkuba Jun 7, 2023
80aef7f
Template for electrumx server
nkuba Jun 7, 2023
25c5fc5
Add electrumx configuration for keep-test cluster
nkuba Jun 7, 2023
75ecd1b
Add namespace for bitcoin on keep-prd
nkuba Jun 7, 2023
c4a0631
Add bitcoind configuration for keep-prd
nkuba Jun 8, 2023
ea169c0
Request 650Gi for mainnet bitcoind
nkuba Jun 8, 2023
15ddca9
Cleanup labels for electrumx statefulset
nkuba Jun 8, 2023
8d68236
Add electrumx server configuration for keep-prd
nkuba Jun 8, 2023
5f4cf9b
Add job for compacting electrumx data
nkuba Jun 8, 2023
1b9d513
Add kube local files to gitignore
nkuba Jun 8, 2023
6400eba
Merge remote-tracking branch 'origin/main' into bitcoin-kube-config
nkuba Jun 8, 2023
cce74bf
Update load balancer IP for electrum
nkuba Jun 8, 2023
1d23f0b
Add envrc file for kube clusters
nkuba Jun 8, 2023
2adb9dd
Remove bcoin configuration
nkuba Jun 8, 2023
7f082d1
Remove bcoin kube config
nkuba Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

# Secret directory used in Kubernetes configurations
/infrastructure/kube/**/.secret/
/infrastructure/kube/**/*.secret

# Backup directory for local copies of Kubernetes configurations
/infrastructure/kube/**/.backup/

# Keys
keystore/
Expand Down
1 change: 1 addition & 0 deletions infrastructure/kube/keep-prd/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export CLOUDSDK_ACTIVE_CONFIG_NAME=keep-prd
4 changes: 4 additions & 0 deletions infrastructure/kube/keep-prd/bitcoin/bitcoin-namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: bitcoin
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: bitcoind-data-bitcoind-1
Copy link
Member

@pdyraga pdyraga Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking at the list of PVCs in GCP and I see bitcoind-data-bitcoind-1 and bitcoind-data-bitcoind-0. To confirm my understanding: we are running two replicas of bitcoind, each with its own PVC. Is this correct? If so, why don't we have bitcoind-data-bitcoind-0-pvc.yaml file here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bitcoind-data-bitcoind-0-pvc got created automatically when we started the bitcoind statefulset with volumeClaimTemplates and just one replica.
After the first replica synced we crated a snapshot of bitcoind-data-bitcoind-0 PVC and used it as a dataSource to create the bitcoind-data-bitcoind-1.

namespace: bitcoin
labels:
app: bitcoind
chain: bitcoin
network: mainnet
spec:
storageClassName: bitcoind
dataSource:
name: bitcoind-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 650Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: bitcoind-snapshot
spec:
volumeSnapshotClassName: bitcoind
source:
persistentVolumeClaimName: bitcoind-data-bitcoind-0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it just for -0? From the PR, I understand that we first synced one instance, then used the snapshots to sync the second instance faster. Long-term, don't we want to have snapshots for both PVCs? If -0 gets corrupted for whatever reason, we could restore it from -1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needed snapshot from bitcoind-data-bitcoind-0 to spin up the second replica. There was no point of creating a snapshot of bitcoind-data-bitcoind-1, as they would be pretty close. After some time I plan to take a new snapshot and repeat it periodically.

31 changes: 31 additions & 0 deletions infrastructure/kube/keep-prd/bitcoin/bitcoind/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resources:
- ../../../templates/bitcoin/bitcoind

namespace: bitcoin

commonLabels:
network: mainnet

configMapGenerator:
- name: bitcoind
behavior: merge
literals:
- chain=main

secretGenerator:
- name: bitcoind
behavior: merge
envs:
- .env.secret

patches:
- target:
kind: StatefulSet
name: bitcoind
patch: |-
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: bitcoind
spec:
replicas: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: batch/v1
kind: Job
metadata:
name: electrumx-compact-history
namespace: bitcoin
labels:
chain: bitcoin
app: electrumx
network: mainnet
spec:
backoffLimit: 0
completions: 1
parallelism: 1
template:
metadata:
labels:
chain: bitcoin
app: electrumx
network: mainnet
job-name: electrumx-compact-history
spec:
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
# https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods
fsGroupChangePolicy: "OnRootMismatch"
containers:
- name: electrumx
image: lukechilds/electrumx:v1.16.0 # TODO: switch to our image
imagePullPolicy: Always
command:
- /electrumx/electrumx_compact_history
env:
- name: COIN
value: BitcoinSegwit
- name: NET
value: mainnet
- name: DB_DIRECTORY
value: /mnt/electrum/data
- name: DAEMON_TOKEN
valueFrom:
secretKeyRef:
name: bitcoind
key: rpc-password
- name: DAEMON_HOST
valueFrom:
configMapKeyRef:
name: electrumx
key: daemon-host
- name: DAEMON_URL
value: http://$(DAEMON_USER):$(DAEMON_TOKEN)@$(DAEMON_HOST)
- name: COST_SOFT_LIMIT
value: "0"
- name: COST_HARD_LIMIT
value: "0"
- name: LOG_LEVEL
value: debug
volumeMounts:
- name: electrumx-data
mountPath: /mnt/electrum/data
restartPolicy: Never
volumes:
- name: electrumx-data
persistentVolumeClaim:
# Update to the desired replica's volume index.
claimName: electrumx-data-electrumx-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: electrumx-data-electrumx-1
namespace: bitcoin
labels:
app: electrumx
chain: bitcoin
network: mainnet
spec:
storageClassName: electrumx-v2
dataSource:
name: electrumx-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 450Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: electrumx-data-electrumx-2
namespace: bitcoin
labels:
app: electrumx
chain: bitcoin
network: mainnet
spec:
storageClassName: electrumx-v2
dataSource:
name: electrumx-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 450Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: electrumx-snapshot
spec:
volumeSnapshotClassName: electrumx
source:
persistentVolumeClaimName: electrumx-data-electrumx-0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about generating snapshots as for bitcoind. Don't we need -1 snapshots as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered here.

43 changes: 43 additions & 0 deletions infrastructure/kube/keep-prd/bitcoin/electrumx/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resources:
- ../../../templates/bitcoin/electrumx

namespace: bitcoin

commonLabels:
network: mainnet

secretGenerator:
- name: tbtc-network-cloudflare-origin-cert
type: kubernetes.io/tls
files:
- .secret/ca.crt
- .secret/tls.crt
- .secret/tls.key

patches:
- target:
kind: Service
name: electrumx
patch: |-
apiVersion: v1
kind: Service
metadata:
name: electrumx
spec:
type: LoadBalancer
loadBalancerIP: 35.223.16.19
- target:
kind: StatefulSet
name: electrumx
patch: |-
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: electrumx
spec:
replicas: 3

generatorOptions:
disableNameSuffixHash: true
annotations:
note: generated
2 changes: 2 additions & 0 deletions infrastructure/kube/keep-prd/bitcoin/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- bitcoin-namespace.yaml
1 change: 1 addition & 0 deletions infrastructure/kube/keep-test/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export CLOUDSDK_ACTIVE_CONFIG_NAME=keep-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: bitcoin-testnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: bitcoind-data-bitcoind-1
namespace: bitcoin-testnet
labels:
app: bitcoind
chain: bitcoin
network: testnet
spec:
storageClassName: bitcoind
dataSource:
name: bitcoind-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: bitcoind-snapshot
spec:
volumeSnapshotClassName: bitcoind
source:
persistentVolumeClaimName: bitcoind-data-bitcoind-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
resources:
- ../../../../templates/bitcoin/bitcoind

namespace: bitcoin-testnet

commonLabels:
network: testnet

configMapGenerator:
- name: bitcoind
behavior: merge
literals:
- chain=test

secretGenerator:
- name: bitcoind
behavior: merge
envs:
- .env.secret

patches:
# Patch bitcoind StatefulSet by setting a storage request specific for testnet.
- target:
kind: StatefulSet
name: bitcoind
patch: |-
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: bitcoind
spec:
replicas: 2
volumeClaimTemplates:
- metadata:
name: bitcoind-data
labels:
chain: bitcoin
app: bitcoind
network: testnet
spec:
storageClassName: bitcoind
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: electrumx-data-electrumx-1
namespace: bitcoin-testnet
labels:
app: electrumx
chain: bitcoin
network: testnet
spec:
storageClassName: electrumx-v2
dataSource:
name: electrumx-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: electrumx-snapshot
spec:
volumeSnapshotClassName: electrumx
source:
persistentVolumeClaimName: electrumx-data-electrumx-0
Loading