-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubernetes-master
315 lines (282 loc) · 8.58 KB
/
kubernetes-master
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#kubernetes-master
#--------------ETCD3-------------------------------
ETCD_VER=v3.2.1
# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/coreos/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_URL}
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/test-etcd && mkdir -p /tmp/test-etcd
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/test-etcd --strip-components=1
/tmp/test-etcd/etcd --version
sudo mkdir -p /opt/bin/
sudo cp /tmp/test-etcd/etcd /opt/bin/etcd3
sudo cp /tmp/test-etcd/etcdctl /opt/bin/etcdctl3
sudo mkdir /var/lib/etcd3
sudo chown etcd:etcd /var/lib/etcd3
sudo bash -c "cat > /etc/systemd/system/etcd3.service <<__EOF__
[Unit]
Description=etcd3
Conflicts=etcd.service
[Service]
User=etcd
Type=notify
Environment=ETCD_DATA_DIR=/var/lib/etcd3
Environment=ETCD_NAME=%m
ExecStart=/opt/bin/etcd3
Restart=always
RestartSec=10s
LimitNOFILE=40000
TimeoutStartSec=0
Environment=ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
Environment=ETCD_ADVERTISE_CLIENT_URLS=http://192.168.0.4:2379
Environment=ETCD_NAME='etcd2'
Environment=ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
Environment=ETCD_INITIAL_ADVERTISE_PEER_URLS=http://192.168.0.4:2380
Environment=ETCD_INITIAL_CLUSTER='etcd0=http://192.168.0.2:2380,etcd1=http://192.168.0.3:2380,etcd2=http://192.168.0.4:2380'
Environment=ETCD_INITIAL_CLUSTER_STATE=new
Environment=ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster-1
[Install]
WantedBy=multi-user.target
__EOF__"
sudo systemctl daemon-reload
sudo systemctl enable etcd3
sudo systemctl start etcd3
#---------------------------------------------
#SSL
sudo mkdir -p /etc/kubernetes/ssl/
sudo chmod 600 /etc/kubernetes/ssl/*-key.pem
sudo chown root:root /etc/kubernetes/ssl/*-key.pem
#------------------------------------------------------
sudo mkdir -p /etc/flannel/
sudo bash -c "cat > /etc/flannel/options.env <<__EOF__
FLANNELD_IFACE=eth1
FLANNELD_ETCD_ENDPOINTS=http://192.168.0.2:2379,http://192.168.0.3:2379,http://192.168.0.4:2379
__EOF__"
sudo mkdir -p /etc/systemd/system/flanneld.service.d
sudo bash -c "cat > /etc/systemd/system/flanneld.service.d/40-ExecStartPre-symlink.conf <<__EOF__
[Service]
ExecStartPre=/usr/bin/ln -sf /etc/flannel/options.env /run/flannel/options.env
__EOF__"
sudo mkdir -p /etc/systemd/system/docker.service.d/
sudo bash -c "cat > /etc/systemd/system/docker.service.d/40-flannel.conf <<__EOF__
[Unit]
Requires=flanneld.service
After=flanneld.service
[Service]
EnvironmentFile=/etc/kubernetes/cni/docker_opts_cni.env
__EOF__"
sudo mkdir -p /etc/kubernetes/cni/net.d
sudo bash -c "cat > /etc/kubernetes/cni/docker_opts_cni.env <<__EOF__
DOCKER_OPT_BIP=""
DOCKER_OPT_IPMASQ=""
__EOF__"
sudo bash -c 'cat > /etc/kubernetes/cni/net.d/10-flannel.conf <<__EOF__
{
"name": "podnet",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
__EOF__'
#-------------------------------------------------
#Kubelet
ADVERTISE_IP=$COREOS_PRIVATE_IPV4
ETCD_ENDPOINTS="http://192.168.0.2:2379,http://192.168.0.3:2379,http://192.168.0.4:2379"
sudo mkdir /etc/kubernetes/manifests
#-----kubelet----------
sudo bash -c 'cat > /etc/systemd/system/kubelet.service <<__EOF__
[Service]
Environment=KUBELET_IMAGE_TAG=v1.6.6_coreos.1
Environment="RKT_RUN_ARGS=--uuid-file-save=/var/run/kubelet-pod.uuid \
--volume var-log,kind=host,source=/var/log \
--mount volume=var-log,target=/var/log \
--volume dns,kind=host,source=/etc/resolv.conf \
--mount volume=dns,target=/etc/resolv.conf"
ExecStartPre=/usr/bin/mkdir -p /etc/kubernetes/manifests
ExecStartPre=/usr/bin/mkdir -p /var/log/containers
ExecStartPre=-/usr/bin/rkt rm --uuid-file=/var/run/kubelet-pod.uuid
ExecStart=/usr/lib/coreos/kubelet-wrapper \
--api-servers=http://127.0.0.1:8080 \
--register-schedulable=false \
--cni-conf-dir=/etc/kubernetes/cni/net.d \
--network-plugin=cni \
--container-runtime=docker \
--allow-privileged=true \
--pod-manifest-path=/etc/kubernetes/manifests \
--hostname-override=192.168.0.4 \
--cluster_dns=10.254.0.100 \
--cluster_domain=cluster.local
ExecStop=-/usr/bin/rkt stop --uuid-file=/var/run/kubelet-pod.uuid
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
__EOF__'
#----api-------------
sudo bash -c 'cat > /etc/kubernetes/manifests/kube-apiserver.yaml <<__EOF__
apiVersion: v1
kind: Pod
metadata:
name: kube-apiserver
namespace: kube-system
spec:
hostNetwork: true
containers:
- name: kube-apiserver
image: quay.io/coreos/hyperkube:v1.6.6_coreos.1
command:
- /hyperkube
- apiserver
- --bind-address=0.0.0.0
- --etcd-servers=http://192.168.0.2:2379,http://192.168.0.3:2379,http://192.168.0.4:2379
- --allow-privileged=true
- --service-cluster-ip-range=10.254.0.0/16
- --secure-port=443
- --advertise-address=192.168.0.4
- --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota
- --tls-cert-file=/etc/kubernetes/ssl/apiserver.pem
- --tls-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --client-ca-file=/etc/kubernetes/ssl/ca.pem
- --service-account-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --runtime-config=extensions/v1beta1/networkpolicies=true
- --anonymous-auth=false
livenessProbe:
httpGet:
host: 127.0.0.1
port: 8080
path: /healthz
initialDelaySeconds: 15
timeoutSeconds: 15
ports:
- containerPort: 443
hostPort: 443
name: https
- containerPort: 8080
hostPort: 8080
name: local
volumeMounts:
- mountPath: /etc/kubernetes/ssl
name: ssl-certs-kubernetes
readOnly: true
- mountPath: /etc/ssl/certs
name: ssl-certs-host
readOnly: true
volumes:
- hostPath:
path: /etc/kubernetes/ssl
name: ssl-certs-kubernetes
- hostPath:
path: /usr/share/ca-certificates
name: ssl-certs-host
__EOF__'
#----------------------------
sudo bash -c "cat > /etc/kubernetes/manifests/kube-proxy.yaml <<__EOF__
apiVersion: v1
kind: Pod
metadata:
name: kube-proxy
namespace: kube-system
spec:
hostNetwork: true
containers:
- name: kube-proxy
image: quay.io/coreos/hyperkube:v1.6.6_coreos.1
command:
- /hyperkube
- proxy
- --master=http://127.0.0.1:8080
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/ssl/certs
name: ssl-certs-host
readOnly: true
volumes:
- hostPath:
path: /usr/share/ca-certificates
name: ssl-certs-host
__EOF__"
#-------------------------
sudo bash -c "cat > /etc/kubernetes/manifests/kube-controller-manager.yaml <<__EOF__
apiVersion: v1
kind: Pod
metadata:
name: kube-controller-manager
namespace: kube-system
spec:
hostNetwork: true
containers:
- name: kube-controller-manager
image: quay.io/coreos/hyperkube:v1.6.6_coreos.1
command:
- /hyperkube
- controller-manager
- --master=http://127.0.0.1:8080
- --leader-elect=true
- --service-account-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --root-ca-file=/etc/kubernetes/ssl/ca.pem
resources:
requests:
cpu: 200m
livenessProbe:
httpGet:
host: 127.0.0.1
path: /healthz
port: 10252
initialDelaySeconds: 15
timeoutSeconds: 15
volumeMounts:
- mountPath: /etc/kubernetes/ssl
name: ssl-certs-kubernetes
readOnly: true
- mountPath: /etc/ssl/certs
name: ssl-certs-host
readOnly: true
volumes:
- hostPath:
path: /etc/kubernetes/ssl
name: ssl-certs-kubernetes
- hostPath:
path: /usr/share/ca-certificates
name: ssl-certs-host
__EOF__"
#------------------
sudo bash -c "cat > /etc/kubernetes/manifests/kube-scheduler.yaml <<__EOF__
apiVersion: v1
kind: Pod
metadata:
name: kube-scheduler
namespace: kube-system
spec:
hostNetwork: true
containers:
- name: kube-scheduler
image: quay.io/coreos/hyperkube:v1.6.6_coreos.1
command:
- /hyperkube
- scheduler
- --master=http://127.0.0.1:8080
- --leader-elect=true
resources:
requests:
cpu: 100m
livenessProbe:
httpGet:
host: 127.0.0.1
path: /healthz
port: 10251
initialDelaySeconds: 15
timeoutSeconds: 15
__EOF__"
#--------------
curl -X PUT -d "value={\"Network\":\"10.31.0.0/16\",\"Backend\":{\"Type\":\"vxlan\"}}" "http://localhost:2379/v2/keys/coreos.com/network/config"
#
sudo systemctl start flanneld
sudo systemctl enable flanneld
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl enable kubelet
#----------------------------