Restore a vFunction Server running via an Operator 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

  1. Use the same values in the Installation.yaml that were used in the previous Server
  2. If possible, use the same DB and Storage PersistentVolumes as in the previous Server
  3. Wait for the installation to complete and for all Pods to come up healthy

Restore the Keys from the original vFunction Server

  1. Copy the MySQL DB Dump to a temporary folder
  2. Extract the DB Dump
  3. 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

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

  1. Go inside vfunction-mysql-xxx pod
  2. Locate the desired dump under /opt/vfunction/backup/ or copy it there
  3. Restore the DB
### Find-and-replace <dump> with the Archived filename

/usr/share/container-scripts/mysql/backup.sh restore <sql-dump-file>

Restart all Pods

Take the following steps using kubectl:

### Note that the variables $identifier and $NAMESPACE were created in
### the section, "Add the original Keys into the new vFunction Server"

kubectl delete deployment vfunction-mysql-$identifier -n $NAMESPACE
kubectl delete deployment vfunction-vfapi-idp-$identifier -n $NAMESPACE
kubectl delete deployment vfunction-vfapi-measurements-$identifier -n $NAMESPACE
kubectl delete deployment vfunction-vfapi-organizations-$identifier -n $NAMESPACE
kubectl delete deployment vfunction-vfapi-parser-$identifier -n $NAMESPACE
kubectl delete deployment vfunction-vfapi-users-$identifier -n $NAMESPACE
kubectl delete deployment vfunction-nginx-$identifier -n $NAMESPACE

Wait for the vFunction Operator to bring back up all pods, and the site will be up with the original vFunction Server data.