Skip to content

Restore k3s from MySQL dump

Article Number: 000020803

Environment

k3s with an external database MySQL (this has been tested using Azure MySQL)

Situation

MySQL DB dump is available, and the cluster token from /var/lib/rancher/k3s/server/token

Resolution

  1. In the new MySQL instance create a database

  2. Here we set the Character set to latin1 and collation to latin1_swedish_ci, as the original DB

  3. we also chose the same name, as it is a new instance
  4. Restore the dump, you may use mysql db_name < backup-file.sql
  5. on the first node start k3s with:

  6. curl -sfL https://get.k3s.io | sh -s - server --token <SERVER-TOKEN> --datastore-endpoint="mysql://<USERNAME>:<PASSWORD>@tcp(<INSTANCE-NAME>.mysql.database.azure.com:3306)/<RESTORED-DB>?tls=true"

  7. the token is retrieve from the failed cluster in /var/lib/rancher/k3s/server/token
  8. Remove the failed nodes running:

  9. k3s kubectl get nodes

  10. k3s kubectl delete nodes <FAILED-NODE>
  11. Join any additional node using the instructions from k3s documentation