This repository has been archived by the owner on Jul 30, 2021. It is now read-only.
/
etcd_template.go
180 lines (177 loc) · 4.54 KB
/
etcd_template.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package recovery
var recoveryEtcdTemplate = []byte(`apiVersion: v1
kind: Pod
metadata:
name: recovery-etcd
namespace: kube-system
labels:
k8s-app: recovery-etcd
spec:
initContainers:
- name: recovery
image: {{ .Image }}
command:
- /usr/local/bin/etcdctl
- snapshot
- restore
- --data-dir=/var/etcd/recovery
- --name=recovery-etcd
- --initial-cluster=recovery-etcd=http://localhost:52380
- --initial-cluster-token=bootkube-recovery
- --initial-advertise-peer-urls=http://localhost:52380
- --skip-hash-check=true
- /var/etcd-backupdir/{{ .BackupFile }}
env:
- name: ETCDCTL_API
value: "3"
volumeMounts:
- mountPath: /var/etcd
name: etcd
readOnly: false
- mountPath: /var/etcd-backupdir
name: etcdbackup
readOnly: false
containers:
- name: etcd
image: {{ .Image }}
command:
- /usr/local/bin/etcd
- --name=recovery-etcd
- --listen-client-urls={{ .ClientAddr }}
- --listen-peer-urls=http://0.0.0.0:52380
- --advertise-client-urls={{ .ClientAddr }}
- --data-dir=/var/etcd/recovery
volumeMounts:
- mountPath: /var/etcd
name: etcd
readOnly: false
hostNetwork: true
restartPolicy: Never
volumes:
- name: etcd
emptyDir: {}
- name: etcdbackup
hostPath:
path: {{ .BackupDir }}
`)
var bootFromBackupEtcdTemplate = []byte(`apiVersion: v1
kind: Pod
metadata:
name: bootstrap-etcd
namespace: kube-system
labels:
k8s-app: boot-etcd
spec:
initContainers:
- name: recovery
image: {{ .Image }}
command:
- /bin/sh
- -ec
- |
etcdctl snapshot restore \
/var/etcd-backupdir/{{ .BackupFile }} \
--data-dir=/var/etcd/data \
--name=boot-etcd \
--initial-cluster=boot-etcd=https://{{ .BootEtcdServiceIP }}:12380 \
--initial-cluster-token={{ .ClusterToken }} \
--initial-advertise-peer-urls=https://{{ .BootEtcdServiceIP }}:12380 \
--skip-hash-check=true
env:
- name: ETCDCTL_API
value: "3"
volumeMounts:
- mountPath: /var/etcd
name: etcd
readOnly: false
- mountPath: /var/etcd-backupdir
name: etcdbackup
readOnly: false
- name: cleanup
image: {{ .Image }}
command:
- /bin/sh
- -ec
- |
(/usr/local/bin/etcd \
--listen-client-urls=http://0.0.0.0:32379 \
--listen-peer-urls=http://0.0.0.0:32380 \
--advertise-client-urls=http://localhost:32379 \
--data-dir=/var/etcd/data &) && sleep 30 && \
etcdctl \
--endpoints=http://localhost:32379 \
del {{ .CRDKey }} && \
etcdctl \
--endpoints=http://localhost:32379 \
del --prefix {{ .MemberPodPrefix }}
env:
- name: ETCDCTL_API
value: "3"
volumeMounts:
- mountPath: /var/etcd
name: etcd
readOnly: false
containers:
- name: etcd
image: {{ .Image }}
command:
- /usr/local/bin/etcd
- --name=boot-etcd
- --listen-client-urls=https://0.0.0.0:12379
- --listen-peer-urls=https://0.0.0.0:12380
- --advertise-client-urls=https://{{ .BootEtcdServiceIP }}:12379
- --data-dir=/var/etcd/data
- --peer-client-cert-auth=true
- --peer-trusted-ca-file=/etc/kubernetes/secrets/etcd/peer-ca.crt
- --peer-cert-file=/etc/kubernetes/secrets/etcd/peer.crt
- --peer-key-file=/etc/kubernetes/secrets/etcd/peer.key
- --client-cert-auth=true
- --trusted-ca-file=/etc/kubernetes/secrets/etcd/server-ca.crt
- --cert-file=/etc/kubernetes/secrets/etcd/server.crt
- --key-file=/etc/kubernetes/secrets/etcd/server.key
volumeMounts:
- mountPath: /var/etcd
name: etcd
readOnly: false
- mountPath: /etc/kubernetes/secrets
name: secrets
readOnly: true
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
restartPolicy: Never
volumes:
- name: etcd
emptyDir: {}
- name: etcdbackup
hostPath:
path: {{ .BackupDir }}
- name: secrets
hostPath:
path: /etc/kubernetes/bootstrap-secrets
`)
var recoveryEtcdSvcTemplate = []byte(`{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "bootstrap-etcd-service",
"namespace": "kube-system"
},
"spec": {
"selector": {
"k8s-app": "boot-etcd"
},
"clusterIP": "{{ .BootEtcdServiceIP }}",
"ports": [
{
"name": "client",
"port": 12379,
"protocol": "TCP"
},
{
"name": "peers",
"port": 12380,
"protocol": "TCP"
}
]
}
}`)