Restore a vFunction Server running via Helm in an Kubernetes Cluster
Overview
In some Kubernetes environments, the Cluster may be repaved at regular intervals. The following steps can be taken to restore a vFunction Server after the Cluster / Namespace has been deleted.
Prerequisites
- A valid MySQL DB Dump to use as a restoration source. These are kept on the MySQL Persistent Volume and can be retrieved from /opt/vfunction/backup/ on that Volume
- Same vFunction Server major version as the MySQL DB Dump, e.g v3.5
Install a new vFunction Server
- Use the same values in the Installation.yaml that were used in the previous Server, including the four generated fields for the client_id, client_secret, app_client_id, app_client_secret
- If possible, use the same DB and Storage PersistentVolumes as in the previous Server
- Wait for the installation to complete and for all Pods to come up healthy
Restore the Keys from the original vFunction Server
NOTE: This section is only need if the generated fields are not in the installation.yaml
- Copy the MySQL DB Dump to a temporary folder
- Extract the DB Dump
- Retrieve the CLIENT_ID, CLIENT_SECRET, APP_CLIENT_ID, and APP_CLIENT_SECRET
### Find-and-replace the string <sql-dump-file>
CLIENT_ID=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f2 | cut -d, -f1 | sed "s~'~~g")
CLIENT_SECRET=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f2 | cut -d, -f2 | sed "s~'~~g")
APP_CLIENT_ID=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f3 | cut -d, -f1 | sed "s~'~~g")
APP_CLIENT_SECRET=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f3 | cut -d, -f2 | sed "s~'~~g")
Add the original Keys into the new vFunction Server
NOTE: These steps are only needed if the generated section is not in the installation.yaml
Modify the configMaps of the new Server to add in the values from the original vFunction Server.
### Find-and-replace the string, <namespace>
NAMESPACE=<namespace>
identifier=$(kubectl get configmap -n $NAMESPACE | grep nginx-custom-env | cut -d' ' -f1 | cut -d- -f4)
kubectl patch configmap vfapi-custom-env.list-$identifier -n $NAMESPACE --type merge -p "{\"data\":{\"CLIENT_ID\":\"$CLIENT_ID\", \"CLIENT_SECRET\":\"$CLIENT_SECRET\"}}"
### Do not run this command below if the environment uses OpenID for Authentication
kubectl patch configmap nginx-custom-env.list-$identifier -n $NAMESPACE --type merge -p "{\"data\":{\"CLIENT_ID\":\"$APP_CLIENT_ID\", \"CLIENT_SECRET\":\"$APP_CLIENT_SECRET\"}}"
kubectl patch configmap nginx-custom-env.list-$identifier -n $NAMESPACE --type merge -p "{\"data\":{\"GENERATED_CLIENT_ID\":\"$APP_CLIENT_ID\", \"GENERATED_CLIENT_SECRET\":\"$APP_CLIENT_SECRET\"}}"
Restore the MySQL DB from the Backup
- Go inside vfunction-mysql-xxx pod
- Locate the desired dump under /opt/vfunction/backup/ or copy it there
- Restore the DB
### Find-and-replace <dump> with the Archived filename
/usr/share/container-scripts/mysql/backup.sh restore <sql-dump-file>
- The site will be up with the original vFunction Server data