-
Notifications
You must be signed in to change notification settings - Fork 1
/
reverse-migrate.sh
executable file
·74 lines (58 loc) · 2.2 KB
/
reverse-migrate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
set -eux
SNAP=/snap/microk8s/current/
SNAP_DATA=/var/snap/microk8s/current/
microk8s.stop
microk8s.enable ha-cluster
microk8s.enable dashboard
cp "$SNAP_DATA"/args/kube-apiserver "$SNAP_DATA"/args/kube-apiserver.backup
cat <<EOT > "$SNAP_DATA"/args/kube-apiserver
--cert-dir=\${SNAP_DATA}/certs
--service-cluster-ip-range=10.152.183.0/24
--authorization-mode=RBAC,Node
--service-account-key-file=\${SNAP_DATA}/certs/serviceaccount.key
--client-ca-file=\${SNAP_DATA}/certs/ca.crt
--tls-cert-file=\${SNAP_DATA}/certs/server.crt
--tls-private-key-file=\${SNAP_DATA}/certs/server.key
--kubelet-client-certificate=\${SNAP_DATA}/certs/server.crt
--kubelet-client-key=\${SNAP_DATA}/certs/server.key
--secure-port=16443
--token-auth-file=\${SNAP_DATA}/credentials/known_tokens.csv
--storage-dir \${SNAP_DATA}/var/kubernetes/backend/
--storage-backend=dqlite
--insecure-port=0
# Enable the aggregation layer
--requestheader-client-ca-file=\${SNAP_DATA}/certs/front-proxy-ca.crt
--requestheader-allowed-names=front-proxy-client
--requestheader-extra-headers-prefix=X-Remote-Extra-
--requestheader-group-headers=X-Remote-Group
--requestheader-username-headers=X-Remote-User
--proxy-client-cert-file=\${SNAP_DATA}/certs/front-proxy-client.crt
--proxy-client-key-file=\${SNAP_DATA}/certs/front-proxy-client.key
#~Enable the aggregation layer
--allow-privileged=true
EOT
systemctl start snap.microk8s.daemon-apiserver
# TODO do some proper wait here
sleep 10
rm -rf db
./migrator --mode backup-dqlite --endpoint "unix:///var/snap/microk8s/current/var/kubernetes/backend/kine.sock" --db-dir db --debug
microk8s.disable ha-cluster
cp "$SNAP_DATA"/args/etcd "$SNAP_DATA"/args/etcd.backup
cat <<EOT > "$SNAP_DATA"/args/etcd
--data-dir=\${SNAP_COMMON}/var/run/etcd
--advertise-client-urls=http://127.0.0.1:12379
--listen-client-urls=http://0.0.0.0:12379
--enable-v2=true
EOT
systemctl restart snap.microk8s.daemon-etcd
sleep 20
./migrator --mode restore-to-etcd --endpoint "http://127.0.0.1:12379" --db-dir db --debug
cp "$SNAP_DATA"/args/kube-apiserver.backup "$SNAP_DATA"/args/kube-apiserver
cp "$SNAP_DATA"/args/etcd.backup "$SNAP_DATA"/args/etcd
sleep 10
microk8s.start