Is there a way to migrate k3s data store endpoint

1.5k Views Asked by At

all

I built up a k3s cluster with K3S_DATASTORE_ENDPOINT=${etcd_cluster_1}, all things go well.

Today, I've change every etcd node's ip in ${etcd_cluster_1} by some reason, so ${etcd_cluster_1} must be changed to ${etcd_cluster_2}

When I restart etcd cluster well and restart k3s, I found waring etcd-0(1,3) not healthy in Rancher.

I think I should migrate ${etcd_cluster_1} to ${etcd_cluster_2}, how can I do this?

2

There are 2 best solutions below

0
On BEST ANSWER

I found that, K3S_DATASTORE_ENDPONT env is stored at /etc/systemd/system/k3s.service.env, I've modified it's content point to the ${etcd_cluster_2} and restarted the k3s with systemctl restart k3s solved this issue.

0
On

Also, you can use the method specified in the docs to backuo a datastore with k3s

Creating Snapshots

The snapshot directory defaults to ${data-dir}/server/db/snapshots. The data-dir value defaults to /var/lib/rancher/k3s and can be changed by setting the --data-dir flag.

k3s etcd-snapshot save

Restoring a Cluster from a Snapshot

When K3s is restored from backup, the old data directory will be moved to ${data-dir}/server/db/etcd-old/. Then K3s will attempt to restore the snapshot by creating a new data directory, then starting etcd with a new K3s cluster with one etcd member.

To restore the cluster from backup:

Single Server

Run K3s with the --cluster-reset option, with the --cluster-reset-restore-path also given:

k3s server \
  --cluster-reset \
  --cluster-reset-restore-path=<PATH-TO-SNAPSHOT>