-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-certificates-etcd
165 lines (143 loc) · 3.82 KB
/
01-certificates-etcd
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
cat > ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "8760h"
},
"profiles": {
"kubernetes": {
"usages": ["signing", "key encipherment", "server auth", "client auth"],
"expiry": "8760h"
}
}
}
}
EOF
cat > ca-csr.json <<EOF
{
"CN": "Kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "US",
"L": "Princeton",
"O": "Kubernetes",
"OU": "NJ",
"ST": "New Jersey"
}
]
}
EOF
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
export KUBERNETES_PUBLIC_IP_ADDRESS='10.240.0.40'
cat > kubernetes-csr.json <<EOF
{
"CN": "*.vmntech.com",
"hosts": [
"10.32.0.1",
"kubem1",
"kubem2",
"kubem1.vmntech.com",
"kubem2.vmntech.com",
"192.168.99.41",
"192.168.99.42",
"kubew1",
"kubew2",
"kubew1.vmntech.com",
"kubew2.vmntech.com",
"192.168.99.51",
"192.168.99.52",
"kubem.vmntech.com",
"kubernetes.vmntech.com",
"192.168.99.40",
"localhost",
"127.0.0.1"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "US",
"L": "Princeton",
"O": "Kubernetes",
"OU": "Cluster",
"ST": "New Jersey"
}
]
}
EOF
cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-profile=kubernetes \
kubernetes-csr.json | cfssljson -bare kubernetes
for i in kubem1 kubem2 kubew1 kubew2; do scp ca.pem kubernetes-key.pem kubernetes.pem root@${i}:/root/ ; done
mkdir -p /etc/etcd/
mv ca.pem kubernetes-key.pem kubernetes.pem /etc/etcd/
curl -L https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz -o etcd-v3.3.9-linux-amd64.tar.gz
tar xzvf etcd-v3.3.9-linux-amd64.tar.gz
cp etcd-v3.3.9-linux-amd64/etcd* /usr/bin/
mkdir -p /data/etcd
on kubem1:
$ cat etcd.service
[Unit]
Description=etcd
Documentation=https://github.com/coreos
[Service]
ExecStart=/usr/bin/etcd --name kubem1 \
--cert-file=/etc/etcd/kubernetes.pem \
--key-file=/etc/etcd/kubernetes-key.pem \
--peer-cert-file=/etc/etcd/kubernetes.pem \
--peer-key-file=/etc/etcd/kubernetes-key.pem \
--trusted-ca-file=/etc/etcd/ca.pem \
--peer-trusted-ca-file=/etc/etcd/ca.pem \
--initial-advertise-peer-urls https://192.168.99.41:2380 \
--listen-peer-urls https://192.168.99.41:2380 \
--listen-client-urls https://192.168.99.41:2379,http://127.0.0.1:2379 \
--advertise-client-urls https://192.168.99.41:2379 \
--initial-cluster-token etcd-cluster-0 \
--initial-cluster kubem1=https://192.168.99.41:2380,kubem2=https://192.168.99.42:2380 \
--initial-cluster-state new \
--data-dir=/data/etcd
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
on kubem2:
$ cat etcd.service
[Unit]
Description=etcd
Documentation=https://github.com/coreos
[Service]
ExecStart=/usr/bin/etcd --name kubem2 \
--cert-file=/etc/etcd/kubernetes.pem \
--key-file=/etc/etcd/kubernetes-key.pem \
--peer-cert-file=/etc/etcd/kubernetes.pem \
--peer-key-file=/etc/etcd/kubernetes-key.pem \
--trusted-ca-file=/etc/etcd/ca.pem \
--peer-trusted-ca-file=/etc/etcd/ca.pem \
--initial-advertise-peer-urls https://192.168.99.42:2380 \
--listen-peer-urls https://192.168.99.42:2380 \
--listen-client-urls https://192.168.99.42:2379,http://127.0.0.1:2379 \
--advertise-client-urls https://192.168.99.42:2379 \
--initial-cluster-token etcd-cluster-0 \
--initial-cluster kubem1=https://192.168.99.41:2380,kubem2=https://192.168.99.42:2380 \
--initial-cluster-state new \
--data-dir=/data/etcd
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
on kubem1/kubem2:
systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
Backup etcd:
# mkdir -p /data/backup
# etcdctl --ca-file=/etc/etcd/ca.pem backup --backup-dir /data/backup/ --data-dir /data/etcd/snap --wal-dir /data/etcd/wal