-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-worker.sh
executable file
·164 lines (138 loc) · 4.58 KB
/
init-worker.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
#!/bin/bash
source /vagrant/common.sh
update_host $2
config_hosts_file
# The socat binary enables support for the kubectl port-forward command.
sudo apt-get -y install socat conntrack
# Download the worker binaries
curl -L -O \
https://github.com/containernetworking/plugins/releases/download/v0.6.0/cni-plugins-amd64-v0.6.0.tgz
curl -L -O \
https://github.com/kubernetes-incubator/cri-containerd/releases/download/v1.0.0-alpha.0/cri-containerd-1.0.0-alpha.0.tar.gz
curl -L -O \
https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl
curl -L -O \
https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kube-proxy
curl -L -O \
https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubelet
# Create installation directories
sudo mkdir -p \
/etc/cni/net.d \
/opt/cni/bin \
/var/lib/kubelet \
/var/lib/kube-proxy \
/var/lib/kubernetes \
/var/run/kubernetes
# Install the worker binaries
sudo tar -xvf cni-plugins-amd64-v0.6.0.tgz -C /opt/cni/bin/
sudo tar -xvf cri-containerd-1.0.0-alpha.0.tar.gz -C /
chmod +x kubectl kube-proxy kubelet
sudo mv kubectl kube-proxy kubelet /usr/local/bin/
# Configure CNI
case "$2" in
worker-01)
POD_CIDR=10.200.1.0/24
# this is needed to address an issue with DNS name resolution
sudo iptables -t nat -I POSTROUTING -s $POD_CIDR -d $POD_CIDR -j MASQUERADE
# add persistent static route
echo -e "\tup route add -net 10.200.2.0 netmask 255.255.255.0 gw 192.168.1.82" |
sudo tee -a /etc/network/interfaces && sudo ifdown enp0s8 && sudo ifup enp0s8
;;
worker-02)
POD_CIDR=10.200.2.0/24
# this is needed to address an issue with DNS name resolution
sudo iptables -t nat -I POSTROUTING -s $POD_CIDR -d $POD_CIDR -j MASQUERADE
# add persistent static route
echo -e "\tup route add -net 10.200.1.0 netmask 255.255.255.0 gw 192.168.1.81" |
sudo tee -a /etc/network/interfaces && sudo ifdown enp0s8 && sudo ifup enp0s8
;;
esac
# create the bridge network configuration
cat > 10-bridge.conf <<EOF
{
"cniVersion": "0.3.1",
"name": "bridge",
"type": "bridge",
"bridge": "cnio0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"ranges": [
[{"subnet": "${POD_CIDR}"}]
],
"routes": [{"dst": "0.0.0.0/0"}]
}
}
EOF
# create the looback network configuration
cat > 99-loopback.conf <<EOF
{
"cniVersion": "0.3.1",
"type": "loopback"
}
EOF
# Move network configuration into the CNI configuration directory
sudo mv 10-bridge.conf 99-loopback.conf /etc/cni/net.d/
# Copy self signed TLS certs into place
sudo cp \
/vagrant/config/${2}-key.pem \
/vagrant/config/${2}.pem /var/lib/kubelet/
sudo cp /vagrant/config/${2}.kubeconfig /var/lib/kubelet/kubeconfig
sudo cp /vagrant/config/ca.pem /var/lib/kubernetes/
# Create the kubelet.service systemd unit file
cat > kubelet.service <<EOF
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=cri-containerd.service
Requires=cri-containerd.service
[Service]
ExecStart=/usr/local/bin/kubelet \\
--fail-swap-on=false \\
--allow-privileged=true \\
--anonymous-auth=false \\
--authorization-mode=Webhook \\
--client-ca-file=/var/lib/kubernetes/ca.pem \\
--cluster-dns=10.32.0.10 \\
--cluster-domain=cluster.local \\
--container-runtime=remote \\
--container-runtime-endpoint=unix:///var/run/cri-containerd.sock \\
--image-pull-progress-deadline=2m \\
--kubeconfig=/var/lib/kubelet/kubeconfig \\
--network-plugin=cni \\
--pod-cidr=${POD_CIDR} \\
--register-node=true \\
--require-kubeconfig \\
--runtime-request-timeout=15m \\
--tls-cert-file=/var/lib/kubelet/${2}.pem \\
--tls-private-key-file=/var/lib/kubelet/${2}-key.pem \\
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# Configure kubernetes proxy service
sudo cp /vagrant/config/kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig
# Create the kube-proxy.service systemd unit file
cat > kube-proxy.service <<EOF
[Unit]
Description=Kubernetes Kube Proxy
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
ExecStart=/usr/local/bin/kube-proxy \\
--cluster-cidr=10.200.0.0/16 \\
--kubeconfig=/var/lib/kube-proxy/kubeconfig \\
--proxy-mode=iptables \\
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# Start the worker services
sudo mv kubelet.service kube-proxy.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable containerd cri-containerd kubelet kube-proxy
sudo systemctl start containerd cri-containerd kubelet kube-proxy