Unchained Snapshot & Restore
Tools Needed
**DO NOT SKIP ANY STEPS IF THIS IS YOUR FIRST TIME GOING THROUGH THE PROCESS**
Manual Snapshot
This process involves scaling down a kubernetes statefulset to ensure no processes are writing to disk and manually taking a snapshot of the ebs volumes in aws. Remember to scale back up the statefulset after the snapshot is taken (no need to wait for the snapshot to complete fully to scale back up)
Manually scale the statefulset of the target coinstack down in k9s
Select the desired namespace with:
:nsand highlight the namespace and press enter
if coinstacks are healthy inunchained-devit is easiest to do it there to avoid any interruptions in productionSelect desired statefulset with:
:stsand highlight the statefulset (ex.ethereum-sts)Scale statefulset with:
s(set replica count to one less than current count and selectOK)This will trigger the statefulset to scale down which will make the ebs volume available for snapshot
Take a snapshot of the target coinstack's EBS volumes in the AWS console
Navigate to
EC2->Elastic Block Store->VolumesSearch by coinstack name (ex.
ethereum) and wait for theVolume stateto showAvailableEBS volumes created by kubernetes do not show a
Name, but you can view theTagsto see what volume you are looking at (namespace and pvc name)Right click and select
Create snapshotEnter the description in the form of
{coinstack}-{service}and selectCreate snapshot(ex.ethereum-indexer,ethereum-daemon,ethereum-daemon-beacon)Repeat for each volume in the coinstack
Manually scale the statefulset of the target coinstack back up in k9s (NOTE: you do not have to wait for the ebs snapshot to complete before scaling back up)
Wait for snapshot to complete
Navigate to
EC2->Elastic Block Store->SnapshotsSnapshot statuswill go fromPending->Complete
Manual Restore
This process involves scaling down a kubenetes statefulset in order to remove any existing pvcs and pvs associated with the replica you wish to restore, creating a new ebs volume from an aws snapshot, and then manually applying a kubernetes yaml file to create a new pvc and pv pointed at the new ebs volume created. Take note of volume size and availability zone to ensure that you recreate the pvc and pv correctly.
Manually scale the statefulset of the target coinstack down in k9s (see above)
Delete the pvc associated with the statefulset replica to be restored
Select desired namespace with:
:nsand highlight the namespace and press enterSelect desired pvc with
:pvcand highlight the pvc (ex.data-daemon-ethereum-sts-0)Take note of the
VOLUMEname to know which pv to delete associated with this pvc (ex.data-daemon-ethereum-sts-0-pv)Delete the pvc with
ctrl+dand selectOK
Delete the pv associated with pvc deleted above
Note:
RECLAIM POLICYindicates whether the pv and associated ebs volume will beRetainorDeleteupon deletion of the pvc. If the pv is not shown after deleting the pvc, this would imply it was set for theDeletepolicySTATUSindicates whether the pv isBound(pvc exists) or isReleased(pvc has been deleted)
Select desired pv with
:pvand highlight the pv (ex.data-daemon-ethereum-sts-0-pv)Take note of the
CLAIMname as another way to see what pvc is associated (format is{namespace}/{pvc_name})Take note of what availability zone the pv is in before deleting (needed for creating the new volume in the correct AZ).
Describe the pv with:
d
Delete the pv with
ctrl+dand selectOK
Create new EBS volume from snapshot
Navigate to
EC2->Elastic Block Store->SnapshotsRight click and select
Create volume from snapshotUse the pre-filled
Volume typeandSizeSelect the correct
Availability ZoneAdd a
Nametag for the specific volume being created in the form ofdata-{service}-{coinstack}-sts-{replicaNumber}and add-devsuffix if it is a coinstack in theunchained-devnamespaceClick
Create volume
Edit the restore-pvc.yaml. This will be used to apply the new kubernetes resources (pvc + pv)
Replace all
<items>with the appropriate data:PersistentVolume.metadata.nameis suffixed with-pv(or-pv-devforunchained-devnamespace)PersistentVolume.spec.capacity.storagemust match the size of the EBS volumePersistentVolume.spec.csi.volumeHandleis theVolume IDof the EBS volumePersistentVolume.spec.nodeAffinity...region must match theAvailability Zoneof the EBS volumePersistentVolumeClaim.metadata.namefollows the format ofdata-{service}-{coinstack}-sts-{replicaNumber}PersistentVolumeClaim.metadata.namespacemust match the namespace of the statefulsetPersistentVolumeClaim.metadata.labels.assetis the coinstack namePersistentVolumeClaim.spec.resources.requests.storagemust match the size of the EBS volumePersistentVolumeClaim.spec.volumeNamemust matchPersistentVolume.metadata.name
Example:
Write the file (don't check in changes after restore is complete)
Apply the yaml to create the new pvc and pv
_You need to be pointing to the correct kube context when applying the yaml. We only have one EKS cluster so you should only have to set the context once. To verify and/or set the context, you can follow these steps:
Verify you are pointing at the correct kube context:
kubectl config current-contextView all available contexts:
kubectl config get-contextsSet kube context:
kubectl config set-context {context_name}
Apply the yaml:
kubectl apply -f path/to/restore-pvc.yamlObserve the pvc and pv are created in k9s
Manually scale the statefulset of the target coinstack back up in k9s (see above)
New ebs volumes take a bit of time to "warm" so initial start up after restore will be slow
Observe the statefulset is syncing and restored successfully