mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #56692 from mborsz/backups
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Modify 'restore-from-backup.sh' to work in multinode etcd cluster. **What this PR does / why we need it**: This PR modifies cluster/restore-from-backup.sh to work in multinode etcd cluster. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
1fcbbd38a7
@ -62,6 +62,9 @@ ETCD_API="$(echo $VERSION_CONTENTS | cut -d '/' -f 2)"
|
|||||||
# NOTE: NAME HAS TO BE EQUAL TO WHAT WE USE IN --name flag when starting etcd.
|
# NOTE: NAME HAS TO BE EQUAL TO WHAT WE USE IN --name flag when starting etcd.
|
||||||
NAME="${NAME:-etcd-$(hostname)}"
|
NAME="${NAME:-etcd-$(hostname)}"
|
||||||
|
|
||||||
|
INITIAL_CLUSTER="${INITIAL_CLUSTER:-${NAME}=http://localhost:2380}"
|
||||||
|
INITIAL_ADVERTISE_PEER_URLS="${INITIAL_ADVERTISE_PEER_URLS:-http://localhost:2380}"
|
||||||
|
|
||||||
# Port on which etcd is exposed.
|
# Port on which etcd is exposed.
|
||||||
etcd_port=2379
|
etcd_port=2379
|
||||||
event_etcd_port=4002
|
event_etcd_port=4002
|
||||||
@ -101,7 +104,7 @@ wait_for_cluster_healthy() {
|
|||||||
# Wait until etcd and apiserver pods are down.
|
# Wait until etcd and apiserver pods are down.
|
||||||
wait_for_etcd_and_apiserver_down() {
|
wait_for_etcd_and_apiserver_down() {
|
||||||
for i in $(seq 120); do
|
for i in $(seq 120); do
|
||||||
etcd=$(docker ps | grep etcd | grep -v etcd-empty-dir | grep -v etcd-monitor | wc -l)
|
etcd=$(docker ps | grep etcd-server | wc -l)
|
||||||
apiserver=$(docker ps | grep apiserver | wc -l)
|
apiserver=$(docker ps | grep apiserver | wc -l)
|
||||||
# TODO: Theoretically it is possible, that apiserver and or etcd
|
# TODO: Theoretically it is possible, that apiserver and or etcd
|
||||||
# are currently down, but Kubelet is now restarting them and they
|
# are currently down, but Kubelet is now restarting them and they
|
||||||
@ -134,6 +137,8 @@ if ! wait_for_etcd_and_apiserver_down; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
read -rsp $'Press enter when all etcd instances are down...\n'
|
||||||
|
|
||||||
# Create the sort of directory structure that etcd expects.
|
# Create the sort of directory structure that etcd expects.
|
||||||
# If this directory already exists, remove it.
|
# If this directory already exists, remove it.
|
||||||
BACKUP_DIR="/var/tmp/backup"
|
BACKUP_DIR="/var/tmp/backup"
|
||||||
@ -185,15 +190,13 @@ elif [ "${ETCD_API}" == "etcd3" ]; then
|
|||||||
|
|
||||||
# Run etcdctl snapshot restore command and wait until it is finished.
|
# Run etcdctl snapshot restore command and wait until it is finished.
|
||||||
# setting with --name in the etcd manifest file and then it seems to work.
|
# setting with --name in the etcd manifest file and then it seems to work.
|
||||||
# TODO(jsz): This command may not work in case of HA.
|
docker run -v ${BACKUP_DIR}:/var/tmp/backup --env ETCDCTL_API=3 \
|
||||||
image=$(docker run -d -v ${BACKUP_DIR}:/var/tmp/backup --env ETCDCTL_API=3 \
|
|
||||||
"gcr.io/google_containers/etcd:${ETCD_VERSION}" /bin/sh -c \
|
"gcr.io/google_containers/etcd:${ETCD_VERSION}" /bin/sh -c \
|
||||||
"/usr/local/bin/etcdctl snapshot restore ${BACKUP_DIR}/${snapshot} --name ${NAME} --initial-cluster ${NAME}=http://localhost:2380; mv /${NAME}.etcd/member /var/tmp/backup/")
|
"/usr/local/bin/etcdctl snapshot restore ${BACKUP_DIR}/${snapshot} --name ${NAME} --initial-cluster ${INITIAL_CLUSTER} --initial-advertise-peer-urls ${INITIAL_ADVERTISE_PEER_URLS}; mv /${NAME}.etcd/member /var/tmp/backup/"
|
||||||
if [ "$?" -ne "0" ]; then
|
if [ "$?" -ne "0" ]; then
|
||||||
echo "Docker container didn't started correctly"
|
echo "Docker container didn't started correctly"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Prepare container exit code: $(docker wait ${image})"
|
|
||||||
|
|
||||||
rm -f "${BACKUP_DIR}/${snapshot}"
|
rm -f "${BACKUP_DIR}/${snapshot}"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user