|
| 1 | +# Data Persistence |
| 2 | + |
| 3 | +By default, Warnet nodes use ephemeral storage, meaning all data is lost when a pod is deleted or restarted. This document describes how to enable persistent storage to be able to use warnet for persistent development environment, such that blockchain data, wallet information, and other node state can survive pod restarts and network redeployments. This is done with Kubernetes Persistent Volume Claims (PVCs), which persist independently of pod lifecycle. |
| 4 | + |
| 5 | +Persistence is available for: |
| 6 | +- **Bitcoin Core** nodes |
| 7 | +- **LND** nodes |
| 8 | +- **CLN** nodes |
| 9 | + |
| 10 | +## Enabling Persistence |
| 11 | + |
| 12 | +Persistence is configured per-node in the network graph definition. Add a `persistence` section to any node's configuration. This creates a new PVC for that node, which is then mounted to the appropriate data directory inside the container. |
| 13 | + |
| 14 | +Also add `restartPolicy: Always` to the node's configuration to ensure that the pod is restarted if it is deleted or crashes. This is important to ensure proper restart after restart of the kubernetes cluster. If there is a risk of hard resets of the cluster, add `reindex=1` to bitcoin_core config to reindex the blockchain on startup and fix potential corrupted chain state. |
| 15 | + |
| 16 | +### Bitcoin Core Node |
| 17 | + |
| 18 | +```yaml |
| 19 | +bitcoin_core: |
| 20 | + image: bitcoincore-27.1:latest |
| 21 | + restartPolicy: Always |
| 22 | + persistence: |
| 23 | + enabled: true |
| 24 | + size: 20Gi # optional, default is 20Gi |
| 25 | + storageClass: "" # optional, default is cluster default storage class |
| 26 | + accessMode: ReadWriteOncePod # optional, default is ReadWriteOncePod. For compatibility with older Kubernetes versions, you may need to set this to ReadWriteOnce |
| 27 | + config: | |
| 28 | + reindex=1 |
| 29 | +``` |
| 30 | +
|
| 31 | +### Lightning Node |
| 32 | +
|
| 33 | +```yaml |
| 34 | +<lnd or cln>: |
| 35 | + image: |
| 36 | + tag: <node-version-tag> |
| 37 | + restartPolicy: Always |
| 38 | + persistence: |
| 39 | + enabled: true |
| 40 | + size: 10Gi # optional, default is 10Gi |
| 41 | + storageClass: "" # optional, default is cluster default storage class |
| 42 | + accessMode: ReadWriteOncePod # optional, default is ReadWriteOncePod. For compatibility with older Kubernetes versions, you may need to set this to ReadWriteOnce |
| 43 | +``` |
| 44 | +
|
| 45 | +## Existing PVCs |
| 46 | +
|
| 47 | +To use custom made PVC or PVC from previous deployment, use the `existingClaim` field to reference an existing PVC by name. If the network configuration or namespace did not change, there is no need to explicitly set the `existingClaim`. The existing PVC is used by default, since its generated name matches the default pattern. To explicitly use a PVC set the name like this: |
| 48 | + |
| 49 | +```yaml |
| 50 | +persistence: |
| 51 | + enabled: true |
| 52 | + existingClaim: "tank-0001.default-bitcoincore-data" |
| 53 | +``` |
| 54 | + |
| 55 | +The generated PVC names follow the pattern: |
| 56 | +`<pod-name>.<namespace>-<node-type>-data` |
| 57 | + |
| 58 | +For example for a bitcoin core node: |
| 59 | +`tank-0001.default-bitcoincore-data` |
| 60 | + |
| 61 | +And for a LND node: |
| 62 | +`tank-0001-ln.default-lnd-data` |
| 63 | + |
| 64 | +Get the list of PVCs in the cluster with `kubectl get pvc -A` and delete any PVCs that are no longer needed with `kubectl delete pvc <pvc-name> -n <namespace>`. |
| 65 | + |
| 66 | +## Mount Paths |
| 67 | + |
| 68 | +When persistence is enabled, the following directories are persisted in the PVCs: |
| 69 | + |
| 70 | +- **Bitcoin Core:** `/root/.bitcoin/` |
| 71 | +- **LND:** `/root/.lnd/` |
| 72 | +- **CLN:** `/root/.lightning/` |
0 commit comments