-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
734 lines (662 loc) · 18.3 KB
/
build.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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#!/bin/bash
WORK_PATH=$(pwd)
export cert=/etc/k8s/cert/etcd/etcd.pem
export key=/etc/k8s/cert/etcd/etcd-key.pem
export ca=/etc/k8s/cert/ca/ca.pem
export peer_cert=/etc/k8s/cert/etcd/etcd.pem
export peer_key=/etc/k8s/cert/etcd/etcd-key.pem
export peer_ca=/etc/k8s/cert/ca/ca.pem
export HOST_IP=192.168.56.105
# etcd cluster "s1=https://192.168.56.105:2380,s2=https://192.168.56.105:2380..."
export ETCD_CLUISTER=
# master node IPs array
MASTER_IPS=()
MASTER_VIP=
# k8s security
K8S_PORT=6443
KUBE_APISERVER="https://${MASTER_VIP}:${K8S_PORT}"
# svc CIDR
SERVICE_CIDR="10.249.0.0/16"
# k8s cluster svc ip , default is the first ip of the svc CIDR
CLUSTER_KUBERNETES_SVC_IP="10.249.0.1"
CLUSTER_DNS="10.249.0.1"
ENCRYPTION_KEY=$(head -c 32 /dev/urandom | base64)
# apiserver
NODE_PORT_RANGE="30000-50000"
# ETCD_ENDPOINTS="https://192.168.10.51:2379,https://192.168.10.52:2379,https://192.168.10.53:2379"
ETCD_ENDPOINTS="https://192.168.56.105:2379"
#kube-controller-manager
## export KUBE_APISERVER="https://${MASTER_VIP}:6443"
export KUBE_APISERVER="https://192.168.56.105:6443"
# Pod 网段,建议 /16 段地址,部署前路由不可达,部署后集群内路由可达(flanneld 保证)
CLUSTER_CIDR=173.47.0.0/16
# flannel
export FLANNEL_ETCD_PREFIX="/kubernetes/network"
CLUSTER_CIDR=173.47.0.0/16
IFACE=enp0s8
#default
CLUSTER_DNS_DOMAIN="cluster.local"
CLUSTER_DNS_SVC_IP="10.249.0.2"
#kube-proxy
export KUBE_APISERVER="https://192.168.56.105:6443"
function usage() {
echo 'this is the edgemesh-iptables usage'
echo "${0} -m MASTER_IPS [-i HIJACK_IP] [-t HIJACK_PORT] [-b EXCLUDE_IP] [-c EXCLUDE_PORT] [-h]"
echo ''
echo ' -m: master ips array with ,'
echo ' -b: Comma separated list of outbound IP for which tarffic is to be redirectd to edgemesh. The'
echo ' wildcard character "*" can be used to configure redirection for all IPs. (default "*")'
echo ' -c: Comma separated list of outbound Port for which tarffic is to be redirectd to edgemesh. The'
echo ' wildcard character "*" can be used to configure redirection for all Ports. (default "*")'
echo ' -d: Comma separated list of outbound IP range in CIDR to be excluded from redirection to edgemesh.'
echo ' The Empty character "" can be used to configure redirection for all IPs. (default "")'
echo ' -e: Comma separated list of outbound Port to be excluded from redirection to edgemesh. The'
echo ' Empty character "" can be used to configure redirection for all Ports. (default "")'
echo ' -f: for some help'
echo ' -g: for some help'
echo ' -h: for some help'
}
function isValidIP() {
if isIPv4 "${1}"; then
true
elif isIPv6 "${1}"; then
true
else
false
fi
}
function isIPv4() {
local ipv4matchString="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
if [[ ${1} =~ ${ipv4matchString} ]]; then
true
else
false
fi
}
function ensure_tools() {
}
function ensure_package() {
}
function generate_cert() {
## verify the tools
if command -v kubectl > /dev/null 2>&1 ; then
#docker build
echo 'kubectl command found'
else
echo 'kubectl command is no found!!'
exit 1
fi
if command -v cfssl > /dev/null 2>&1 ; then
#docker build
echo 'cfssl command found'
else
echo 'cfssl command is no found!!'
exit 1
fi
if command -v cfssljson > /dev/null 2>&1 ; then
#docker build
echo 'cfssljson command found'
else
echo 'cfssljson command is no found!!'
exit 1
fi
if command -v cfssl-certinfo > /dev/null 2>&1 ; then
#docker build
echo 'cfssl-certinfo command found'
else
echo 'cfssl-certinfo command is no found!!'
exit 1
fi
mkdir ${WORK_PATH}/cert
# CA
mkdir ${WORK_PATH}/cert/ca
cat > ${WORK_PATH}/cert/ca/ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "87600h"
},
"profiles": {
"kubernetes": {
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
],
"expiry": "87600h"
}
}
}
}
EOF
cat > ${WORK_PATH}/cert/ca/ca-csr.json <<EOF
{
"CN": "kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cd ${WORK_PATH}/cert/ca/
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
echo '============================================================'
echo 'ca certificate generate successful'
echo '============================================================'
# etcd
mkdir ${WORK_PATH}/cert/etcd
cat > ${WORK_PATH}/cert/etcd/etcd-csr.json <<EOF
{
"CN": "etcd",
"hosts": [
"127.0.0.1",
"${MASTER_IPS[0]}",
"${MASTER_IPS[1]}",
"${MASTER_IPS[2]}"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cd ${WORK_PATH}/cert/etcd/
cfssl gencert -ca=${WORK_PATH}/cert/ca/ca.pem \
-ca-key=${WORK_PATH}/cert/ca/ca-key.pem \
-config=${WORK_PATH}/cert/ca/ca-config.json \
-profile=kubernetes etcd-csr.json | cfssljson -bare etcd
echo '============================================================'
echo 'etcd certificate generate successful!!'
echo '============================================================'
#kubectl
mkdir ${WORK_PATH}/cert/admin
cat > ${WORK_PATH}/cert/admin/admin-csr.json <<EOF
{
"CN": "admin",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "system:masters",
"OU": "System"
}
]
}
EOF
cd ${WORK_PATH}/cert/admin/
cfssl gencert -ca= ${WORK_PATH}/cert/ca/ca.pem \
-ca-key= ${WORK_PATH}/cert/ca/ca-key.pem \
-config= ${WORK_PATH}/cert/ca/ca-config.json \
-profile=kubernetes admin-csr.json | cfssljson -bare admin
kubectl config set-cluster kubernetes \
--certificate-authority= ${WORK_PATH}/cert/ca/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER}
kubectl config set-credentials admin \
--client-certificate= ${WORK_PATH}/cert/admin/admin.pem \
--client-key= ${WORK_PATH}/cert/admin/admin-key.pem \
--embed-certs=true
kubectl config set-context kubernetes \
--cluster=kubernetes \
--user=admin
kubectl config use-context kubernetes
echo '============================================================'
echo 'kubectl certificate generate successful!!'
echo '============================================================'
# kube-apiserver
mkdir -p ${WORK_PATH}/cert/kubernetes/
cat > ${WORK_PATH}/cert/kubernetes/kubernetes-csr.json <<EOF
{
"CN": "kubernetes",
"hosts": [
"127.0.0.1",
"${MASTER_IPS[0]}",
"${MASTER_IPS[1]}",
"${MASTER_IPS[2]}",
"${CLUSTER_KUBERNETES_SVC_IP}",
"kubernetes",
"kubernetes.default",
"kubernetes.default.svc",
"kubernetes.default.svc.cluster",
"kubernetes.default.svc.cluster.local",
"kubernetes.default.svc.${CLUSTER_DNS_DOMAIN}"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cd ${WORK_PATH}/cert/kubernetes/
cfssl gencert -ca=${WORK_PATH}/cert/ca/ca.pem \
-ca-key=${WORK_PATH}cert/ca/ca-key.pem \
-config=${WORK_PATH}cert/ca/ca-config.json \
-profile=kubernetes kubernetes-csr.json | cfssljson -bare kubernetes
mkdir -p ${WORK_PATH}/cert/kubernetes/yaml
cat > ${WORK_PATH}/cert/kube-apiserver/yaml/encryption-config.yaml <<EOF
kind: EncryptionConfig
apiVersion: v1
resources:
- resources:
- secrets
providers:
- aescbc:
keys:
- name: key1
secret: ${ENCRYPTION_KEY}
- identity: {}
EOF
mkdir -p ${WORK_PATH}/cert/kubernetes/boostrap
cat <<EOF >${WORK_PATH}/cert/kube-apiserver/boostrap/bootstrap-token.csv
${ENCRYPTION_KEY},kubelet-bootstrap,10001,"system:kubelet-bootstrap"
EOF
cat <<EOF >${WORK_PATH}/cert/kubernetes/boostrap/basic-auth.csv
admin,admin,1
readonly,readonly,2
EOF
echo '============================================================'
echo 'kube-apiserver certificate generate successful!!'
echo '============================================================'
# kube-controller-manager
mkdir -p ${WORK_PATH}/cert/kube-controller-manager/
cat > ${WORK_PATH}/cert/kube-controller-manager/kube-controller-manager-csr.json <<EOF
{
"CN": "system:kube-controller-manager",
"key": {
"algo": "rsa",
"size": 2048
},
"hosts": [
"127.0.0.1",
"${MASTER_IPS[0]}",
"${MASTER_IPS[1]}",
"${MASTER_IPS[2]}"
],
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "system:kube-controller-manager",
"OU": "System"
}
]
}
EOF
cd mkdir -p ${WORK_PATH}/cert/kube-controller-manager
cfssl gencert -ca=${WORK_PATH}/cert/ca/ca.pem \
-ca-key=${WORK_PATH}/cert/ca/ca-key.pem \
-config=${WORK_PATH}/cert/ca/ca-config.json \
-profile=kubernetes kube-controller-manager-csr.json | cfssljson -bare kube-controller-manager
kubectl config set-cluster kubernetes \
--certificate-authority==${WORK_PATH}/cert/ca/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=kube-controller-manager.kubeconfig
kubectl config set-credentials system:kube-controller-manager \
--client-certificate=${WORK_PATH}/cert/kube-controller-manager/kube-controller-manager.pem \
--client-key=${WORK_PATH}/cert/kube-controller-manager/kube-controller-manager-key.pem \
--embed-certs=true \
--kubeconfig=kube-controller-manager.kubeconfig
kubectl config set-context system:kube-controller-manager \
--cluster=kubernetes \
--user=system:kube-controller-manager \
--kubeconfig=kube-controller-manager.kubeconfig
kubectl config use-context system:kube-controller-manager --kubeconfig=kube-controller-manager.kubeconfig
echo '============================================================'
echo 'kube-controller-manager certificate generate successful!!'
echo '============================================================'
# kube-scheduler
mkdir -p ${WORK_PATH}/cert/ kube-scheduler/
cat > ${WORK_PATH}/cert/ kube-scheduler/kube-scheduler-csr.json <<EOF
{
"CN": "system:kube-scheduler",
"hosts": [
"127.0.0.1",
"${MASTER_IPS[0]}",
"${MASTER_IPS[1]}",
"${MASTER_IPS[2]}"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "system:kube-scheduler",
"OU": "System"
}
]
}
EOF
cd ${WORK_PATH}/cert/ kube-scheduler/
cfssl gencert -ca=${WORK_PATH}/cert/ca/ca.pem \
-ca-key=${WORK_PATH}/cert/ca/ca-key.pem \
-config=${WORK_PATH}/cert/ca/ca-config.json \
-profile=kubernetes kube-scheduler-csr.json | cfssljson -bare kube-scheduler
kubectl config set-cluster kubernetes \
--certificate-authority=${WORK_PATH}/cert/ca/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=kube-scheduler.kubeconfig
kubectl config set-credentials system:kube-scheduler \
--client-certificate=./kube-scheduler.pem \
--client-key=./kube-scheduler-key.pem \
--embed-certs=true \
--kubeconfig=kube-scheduler.kubeconfig
kubectl config set-context system:kube-scheduler \
--cluster=kubernetes \
--user=system:kube-scheduler \
--kubeconfig=kube-scheduler.kubeconfig
kubectl config use-context system:kube-scheduler --kubeconfig=kube-scheduler.kubeconfig
echo '============================================================'
echo 'kube-scheduler certificate generate successful!!'
echo '============================================================'
# flannel
mkdir -p ${WORK_PATH}/cert/flannel/
cat > ${WORK_PATH}/cert/flannel/flanneld-csr.json <<EOF
{
"CN": "flanneld",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cd ${WORK_PATH}/cert/flannel/
cfssl gencert -ca=${WORK_PATH}/cert/ca/ca.pem \
-ca-key=${WORK_PATH}/cert/ca/ca-key.pem \
-config=${WORK_PATH}/cert/ca/ca-config.json \
-profile=kubernetes flanneld-csr.json | cfssljson -bare flanneld
echo '============================================================'
echo 'flannel certificate generate successful!!'
echo '============================================================'
rm -rf /var/k8s/cert/
mkdir -p /var/k8s/cert/
cp -rf ${WORK_PATH}/cert/* /var/k8s/cert/
cd ${WORK_PATH}/
tar -zcvf cert.tar.gz ${WORK_PATH}/cert/*
echo '============================================================'
echo 'certificate generate successful!!'
echo '============================================================'
}
function prepare_cni_plugin() {
sudo wget https://github.com/containernetworking/plugins/releases/download/v0.7.1/cni-plugins-amd64-v0.7.1.tgz -P /usr/local/src
mkdir -p /usr/local/k8s/bin/cni
tar zxf /usr/local/src/cni-plugins-amd64-v0.7.1.tgz -C /usr/local/k8s/bin/cni
chmod +x /usr/local/k8s/bin/cni/*
sudo mkdir -p /etc/cni/net.d
sudo bash -c "cat > /etc/cni/net.d/10-default.conf" <<EOF
{
"name": "flannel",
"type": "flannel",
"delegate": {
"bridge": "cni0",
"isDefaultGateway": true,
"mtu": 1400
}
}
EOF
}
function prepare_kubelet() {
#worker_name=${1}
#KUBE_APISERVER=${2}
if command -v kubectl > /dev/null 2>&1 ; then
#docker build
echo 'kubectl command found'
else
echo 'kubectl command is no found!!'
exit 1
fi
if command -v kubeadm > /dev/null 2>&1 ; then
#docker build
echo 'kubeadm command found'
else
echo 'kubeadm command is no found!!'
exit 1
fi
echo "work name: ${worker_name}"
echo "KUBE_APISERVER : ${KUBE_APISERVER}"
if [ "${worker_name}" = "" ]; then
exit 0
fi
if [ "${KUBE_APISERVER}" = "" ]; then
exit 0
fi
cd ${WORK_PATH}
mkdir -p ${WORK_PATH}/kubelet/${worker_name}
cd ${WORK_PATH}/kubelet/${worker_name}
# 创建 token
export BOOTSTRAP_TOKEN=$(kubeadm token create \
--description kubelet-bootstrap-token \
--groups system:bootstrappers:${worker_name} \
--kubeconfig ~/.kube/config)
# 设置集群参数
kubectl config set-cluster kubernetes \
--certificate-authority=/var/k8s/cert/ca/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=kubelet-bootstrap.kubeconfig
# 设置客户端认证参数
kubectl config set-credentials kubelet-bootstrap \
--token=${BOOTSTRAP_TOKEN} \
--kubeconfig=kubelet-bootstrap.kubeconfig
# 设置上下文参数
kubectl config set-context default \
--cluster=kubernetes \
--user=kubelet-bootstrap \
--kubeconfig=kubelet-bootstrap.kubeconfig
# 设置默认上下文
kubectl config use-context default --kubeconfig=kubelet-bootstrap.kubeconfig
cat > ${WORK_PATH}/kubelet/${worker_name}/kubelet.config.json <<EOF
{
"kind": "KubeletConfiguration",
"apiVersion": "kubelet.config.k8s.io/v1beta1",
"authentication": {
"x509": {
"clientCAFile": " ${WORK_PATH}/cert/ca/ca.pem"
},
"webhook": {
"enabled": true,
"cacheTTL": "2m0s"
},
"anonymous": {
"enabled": false
}
},
"authorization": {
"mode": "Webhook",
"webhook": {
"cacheAuthorizedTTL": "5m0s",
"cacheUnauthorizedTTL": "30s"
}
},
"address": "${worker_name}",
"port": 10250,
"readOnlyPort": 0,
"cgroupDriver": "systemd",
"hairpinMode": "promiscuous-bridge",
"serializeImagePulls": false,
"featureGates": {
"RotateKubeletClientCertificate": true,
"RotateKubeletServerCertificate": true
},
"clusterDomain": "${CLUSTER_DNS_DOMAIN}",
"clusterDNS": [${CLUSTER_DNS_SVC_IP}]
}
EOF
}
function prepare_kubeproxy(){
cat > ./kube-proxy-csr.json <<EOF
{
"CN": "system:kube-proxy",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cfssl gencert -ca=/var/k8s/cert/ca/ca.pem \
-ca-key=/var/k8s/cert/ca/ca-key.pem \
-config=/var/k8s/cert/ca/ca-config.json \
-profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy
kubectl config set-cluster kubernetes \
--certificate-authority=/var/k8s/cert/ca/ca.pem \
--embed-certs=true \
--server="https://192.168.56.105:6443" \
--kubeconfig=kube-proxy.kubeconfig
# 设置客户端认证参数
kubectl config set-credentials kube-proxy \
--client-certificate=/var/k8s/cert/kube-proxy/kube-proxy.pem \
--client-key=/var/k8s/cert/kube-proxy/kube-proxy-key.pem \
--embed-certs=true \
--kubeconfig=kube-proxy.kubeconfig
# --embed-certs=true 将 ca.pem 和 admin.pem 证书内容嵌入到生成的 kubectl-proxy.kubeconfig 文件中(不加时,写入的是证书文件路径);
# 设置上下文参数
kubectl config set-context default \
--cluster=kubernetes \
--user=kube-proxy \
--kubeconfig=kube-proxy.kubeconfig
# 设置默认上下文
kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
cat > ./kube-proxy.config.yaml <<EOF
apiVersion: kubeproxy.config.k8s.io/v1alpha1
bindAddress: 192.168.56.105
clientConnection:
kubeconfig: /usr/local/k8s/conf/kube-proxy.kubeconfig
clusterCIDR: 173.47.0.0/16
healthzBindAddress: 192.168.56.105:10256
hostnameOverride: 192.168.56.105
kind: KubeProxyConfiguration
metricsBindAddress: 192.168.56.105:10249
mode: "ipvs"
EOF
}
function install_flannel(){
}
function prepare_addon() {
}
function build_images() {
if command -v docker > /dev/null 2>&1 ; then
#docker build
echo 'docker command found'
else
echo 'docker command is no found!!'
exit 1
fi
}
function main() {
while getopts ":m:t:v:b:c:h" opt; do
case ${opt} in
m)
masterips=${OPTARG}
;;
t)
type=${OPTARG}
;;
v)
vip=${OPTARG}
;;
b)
EDGEMESH_EXCLUDE_IP=${OPTARG}
;;
c)
EDGEMESH_EXCLUDE_PORT=${OPTARG}
;;
h)
usage
exit 0
;;
?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 1
;;
esac
done
if [ "${masterips}" = "" ]; then
echo 'please specify the master node ips'
exit 1
fi
splt='/*'
# parse parameter
IFS=',' read -ra tmp_ip <<< "${masterips}"
# echo "EXCLUDE_IP: ${EXCLUDE_IP}"
for range in "${tmp_ip[@]}"; do
r=${range%$splt}
if isValidIP "$r"; then
if isIPv4 "$r"; then
MASTER_IPS=("$range")
fi
fi
done
if [ "${type}" = "" ]; then
echo 'please specify the mode of the k8s cluster. single or ha'
exit 1
fi
if [ "${type}" = "single" ]; then
MASTER_VIP=${MASTER_IPS[0]}
elif [ "${type}" = "ha" ]; then
MASTER_VIP=${vip}
else
echo 'mode is invalid'
exit 1
fi
}
main "${@}"