Skip to content

Commit 563ecdf

Browse files
committed
Merge pull request #3 from bakins/cleanup
general code cleanup
2 parents b277ba7 + 67f2797 commit 563ecdf

File tree

3 files changed

+85
-60
lines changed

3 files changed

+85
-60
lines changed

scripts/functions.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,29 @@ setup-install-etcd() {
2020
chmod +x /opt/bin/install-etcd
2121
}
2222

23+
setup-install-kubernetes() {
24+
mkdir -p /opt/bin
25+
cp $DIR/install-kubernetes /opt/bin/install-kubernetes
26+
chmod +x /opt/bin/install-kubernetes
27+
cat <<EOF > /etc/systemd/system/install-kubernetes.service
28+
[Unit]
29+
Description=Install Kubernetes
30+
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
31+
Requires=network-online.target
32+
After=network-online.target
33+
34+
[Service]
35+
ExecStart=/opt/bin/install-kubernetes
36+
Type=oneshot
37+
RemainAfterExit=true
38+
39+
[Install]
40+
WantedBy=multi-user.target
41+
EOF
42+
}
43+
44+
setup-wupiao() {
45+
mkdir -p /opt/bin
46+
cp $DIR/wupiao /opt/bin/wupiao
47+
chmod +x /opt/bin/wupiao
48+
}

scripts/master.sh

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,29 @@ source /etc/kubernetes.env
66

77
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
88

9-
start() {
10-
systemctl daemon-reload
11-
systemctl enable ${1}.service
12-
systemctl start ${1}.service
13-
}
14-
15-
mkdir -p /etc/systemd/system/etcd2.service.d
16-
cat <<EOF > /etc/systemd/system/etcd2.service.d/50-etcd.conf
17-
[Service]
18-
Environment=ETCD_PROXY=on
19-
EnvironmentFile=/etc/kubernetes.env
20-
21-
[Install]
22-
WantedBy=multi-user.target
23-
EOF
9+
source $DIR/functions.sh
2410

25-
mkdir -p /opt/bin
11+
setup-install-etcd
12+
setup-install-kubernetes
13+
setup-wupiao
2614

27-
cp $DIR/install-kubernetes /opt/bin/install-kubernetes
28-
chmod +x /opt/bin/install-kubernetes
29-
30-
cp $DIR/wupiao /opt/bin/wupiao
31-
chmod +x /opt/bin/wupiao
32-
33-
34-
cat <<EOF > /etc/systemd/system/install-kubernetes.service
15+
cat <<'EOF' > /etc/systemd/system/etcd.service
3516
[Unit]
36-
Description=Install Kubernetes
37-
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
38-
Requires=network-online.target
39-
After=network-online.target
17+
Description=etcd
4018
4119
[Service]
42-
ExecStart=/opt/bin/install-kubernetes
43-
Type=oneshot
44-
RemainAfterExit=true
20+
Environment=ETCD_PROXY=on
21+
EnvironmentFile=/etc/kubernetes.env
22+
ExecStartPre=/opt/bin/install-etcd
23+
ExecStart=/opt/bin/etcd
24+
Restart=always
25+
RestartSec=10s
26+
LimitNOFILE=40000
4527
4628
[Install]
4729
WantedBy=multi-user.target
4830
EOF
4931

50-
5132
cat <<EOF > /etc/systemd/system/kube-apiserver.service
5233
[Unit]
5334
Description=Kubernetes API Server
@@ -77,8 +58,8 @@ EOF
7758
mkdir -p /etc/systemd/system/flanneld.service.d
7859
cat <<EOF > /etc/systemd/system/flanneld.service.d/50-network-config.conf
7960
[Unit]
80-
Requires=etcd2.service
81-
After=etcd2.service
61+
Requires=etcd.service
62+
After=etcd.service
8263
8364
[Service]
8465
EnvironmentFile=/etc/kubernetes.env
@@ -132,6 +113,6 @@ RestartSec=10
132113
WantedBy=multi-user.target
133114
EOF
134115

135-
for S in etcd2 flanneld kube-apiserver kube-scheduler kube-controller-manager; do
116+
for S in etcd flanneld kube-apiserver kube-scheduler kube-controller-manager; do
136117
start $S
137118
done

scripts/worker.sh

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,34 @@ set -x
55
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
66

77
source /etc/kubernetes.env
8+
source $DIR/functions.sh
89

9-
start() {
10-
systemctl daemon-reload
11-
systemctl enable ${1}.service
12-
systemctl start ${1}.service
13-
}
10+
setup-install-etcd
11+
setup-install-kubernetes
12+
setup-wupiao
13+
14+
cat <<'EOF' > /etc/systemd/system/etcd.service
15+
[Unit]
16+
Description=etcd
1417
15-
mkdir -p /etc/systemd/system/etcd2.service.d
16-
cat <<'EOF' > /etc/systemd/system/etcd2.service.d/50-etcd.conf
1718
[Service]
1819
Environment=ETCD_PROXY=on
1920
EnvironmentFile=/etc/kubernetes.env
20-
EOF
21-
22-
start etcd2
23-
24-
mkdir -p /opt/bin
25-
26-
cp $DIR/install-kubernetes /opt/bin/install-kubernetes
27-
chmod +x /opt/bin/install-kubernetes
28-
29-
cp $DIR/wupiao /opt/bin/wupiao
30-
chmod +x /opt/bin/wupiao
21+
ExecStartPre=/opt/bin/install-etcd
22+
ExecStart=/opt/bin/etcd
23+
Restart=always
24+
RestartSec=10s
25+
LimitNOFILE=40000
3126
32-
/opt/bin/wupiao http://127.0.0.1:2379/v2/members
27+
[Install]
28+
WantedBy=multi-user.target
29+
EOF
3330

3431
mkdir -p /etc/systemd/system/flanneld.service.d
3532
cat <<'EOF' > /etc/systemd/system/flanneld.service.d/50-network-config.conf
3633
[Unit]
37-
Requires=etcd2.service
38-
After=etcd2.service
34+
Requires=etcd.service
35+
After=etcd.service
3936
4037
[Service]
4138
ExecStartPre=/opt/bin/wupiao http://127.0.0.1:2379/v2/members
@@ -44,9 +41,6 @@ ExecStartPre=/opt/bin/wupiao http://127.0.0.1:2379/v2/members
4441
WantedBy=multi-user.target
4542
EOF
4643

47-
start flanneld
48-
start docker
49-
5044
cat <<'EOF' > /etc/systemd/system/install-kubernetes.service
5145
[Unit]
5246
Description=Install Kubernetes
@@ -87,7 +81,26 @@ RestartSec=10
8781
WantedBy=multi-user.target
8882
EOF
8983

90-
start kube-kubelet
84+
cat <<'EOF' > /etc/systemd/system/kube-proxy.service
85+
[Unit]
86+
Description=Kubernetes Proxy Server
87+
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
88+
After=install-kubernetes.service
89+
Requires=install-kubernetes.service
90+
91+
[Service]
92+
EnvironmentFile=/etc/kubernetes.env
93+
ExecStartPre=/opt/bin/wupiao ${KUBERNETES_MASTER}/api/v1beta3/nodes
94+
ExecStart=/opt/bin/kubelet \
95+
--master==${KUBERNETES_MASTER}
96+
--logtostderr=true \
97+
--v=2
98+
Restart=on-failure
99+
RestartSec=10
100+
101+
[Install]
102+
WantedBy=multi-user.target
103+
EOF
91104

92105
H=`hostname -f`
93106
cat <<EOF > /tmp/node.json
@@ -100,6 +113,11 @@ cat <<EOF > /tmp/node.json
100113
}
101114
EOF
102115

116+
117+
for S in etcd flanneld docker kube-kubelet kube-proxy; do
118+
start $S
119+
done
120+
103121
/opt/bin/wupiao ${KUBERNETES_MASTER}/api/v1beta3/nodes
104122
kubectl --server=${KUBERNETES_MASTER} create -f /tmp/node.json
105123

0 commit comments

Comments
 (0)