14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
- # A scripts to install k8s worker node .
18
- # Author @wizard_cxy @reouser
17
+ # A script to setup the k8s master in docker containers .
18
+ # Authors @wizard_cxy @resouer
19
19
20
20
set -e
21
21
@@ -26,12 +26,10 @@ if ( ! ps -ef | grep "/usr/bin/docker" | grep -v 'grep' &> /dev/null ); then
26
26
fi
27
27
28
28
# Make sure k8s version env is properly set
29
- if [ -z ${K8S_VERSION} ]; then
30
- K8S_VERSION=" 1.0.7"
31
- echo " K8S_VERSION is not set, using default: ${K8S_VERSION} "
32
- else
33
- echo " k8s version is set to: ${K8S_VERSION} "
34
- fi
29
+ K8S_VERSION=${K8S_VERSION:- " 1.1.3" }
30
+ ETCD_VERSION=${ETCD_VERSION:- " 2.2.1" }
31
+ FLANNEL_VERSION=${FLANNEL_VERSION:- " 0.5.5" }
32
+ FLANNEL_IFACE=${FLANNEL_IFACE:- " eth0" }
35
33
36
34
# Run as root
37
35
if [ " $( id -u) " != " 0" ]; then
41
39
42
40
# Make sure master ip is properly set
43
41
if [ -z ${MASTER_IP} ]; then
44
- echo " Please export MASTER_IP in your env"
45
- exit 1
46
- else
47
- echo " k8s master is set to: ${MASTER_IP} "
42
+ MASTER_IP=$( hostname -I | awk ' {print $1}' )
48
43
fi
49
44
45
+ echo " K8S_VERSION is set to: ${K8S_VERSION} "
46
+ echo " ETCD_VERSION is set to: ${ETCD_VERSION} "
47
+ echo " FLANNEL_VERSION is set to: ${FLANNEL_VERSION} "
48
+ echo " FLANNEL_IFACE is set to: ${FLANNEL_IFACE} "
49
+ echo " MASTER_IP is set to: ${MASTER_IP} "
50
+
50
51
# Check if a command is valid
51
52
command_exists () {
52
53
command -v " $@ " > /dev/null 2>&1
@@ -95,16 +96,17 @@ detect_lsb() {
95
96
96
97
97
98
# Start the bootstrap daemon
99
+ # TODO: do not start docker-bootstrap if it's already running
98
100
bootstrap_daemon () {
99
- sudo -b docker -d \
100
- -H unix:///var/run/docker-bootstrap.sock \
101
- -p /var/run/docker-bootstrap.pid \
102
- --iptables=false \
103
- --ip-masq=false \
104
- --bridge=none \
105
- --graph=/var/lib/docker-bootstrap \
106
- 2> /var/log/docker-bootstrap.log \
107
- 1> /dev/null
101
+ docker -d \
102
+ -H unix:///var/run/docker-bootstrap.sock \
103
+ -p /var/run/docker-bootstrap.pid \
104
+ --iptables=false \
105
+ --ip-masq=false \
106
+ --bridge=none \
107
+ --graph=/var/lib/docker-bootstrap \
108
+ 2> /var/log/docker-bootstrap.log \
109
+ 1> /dev/null &
108
110
109
111
sleep 5
110
112
}
@@ -115,34 +117,34 @@ DOCKER_CONF=""
115
117
start_k8s (){
116
118
# Start etcd
117
119
docker -H unix:///var/run/docker-bootstrap.sock run \
118
- --restart=always \
119
- --net=host \
120
- -d \
121
- gcr.io/google_containers/etcd:2.2.1 \
122
- /usr/local/bin/etcd \
123
- --listen-client-urls=http://127.0.0.1:4001,http://${MASTER_IP} :4001 \
124
- --advertise-client-urls=http://${MASTER_IP} :4001 \
125
- --data-dir=/var/etcd/data
120
+ --restart=always \
121
+ --net=host \
122
+ -d \
123
+ gcr.io/google_containers/etcd:${ETCD_VERSION} \
124
+ /usr/local/bin/etcd \
125
+ --listen-client-urls=http://127.0.0.1:4001,http://${MASTER_IP} :4001 \
126
+ --advertise-client-urls=http://${MASTER_IP} :4001 \
127
+ --data-dir=/var/etcd/data
126
128
127
129
sleep 5
128
130
# Set flannel net config
129
131
docker -H unix:///var/run/docker-bootstrap.sock run \
130
- --net=host gcr.io/google_containers/etcd:2.2.1 \
131
- etcdctl \
132
- set /coreos.com/network/config \
133
- ' { "Network": "10.1.0.0/16", "Backend": {"Type": "vxlan"}}'
132
+ --net=host gcr.io/google_containers/etcd:${ETCD_VERSION} \
133
+ etcdctl \
134
+ set /coreos.com/network/config \
135
+ ' { "Network": "10.1.0.0/16", "Backend": {"Type": "vxlan"}}'
134
136
135
137
# iface may change to a private network interface, eth0 is for default
136
138
flannelCID=$( docker -H unix:///var/run/docker-bootstrap.sock run \
137
- --restart=always \
138
- -d \
139
- --net=host \
140
- --privileged \
141
- -v /dev/net:/dev/net \
142
- quay.io/coreos/flannel:0.5.5 \
143
- /opt/bin/flanneld \
144
- --ip-masq \
145
- - iface=" eth0 " )
139
+ --restart=always \
140
+ -d \
141
+ --net=host \
142
+ --privileged \
143
+ -v /dev/net:/dev/net \
144
+ quay.io/coreos/flannel:${FLANNEL_VERSION} \
145
+ /opt/bin/flanneld \
146
+ --ip-masq \
147
+ -- iface=" ${FLANNEL_IFACE} " )
146
148
147
149
sleep 8
148
150
@@ -155,13 +157,13 @@ start_k8s(){
155
157
case " ${lsb_dist} " in
156
158
amzn)
157
159
DOCKER_CONF=" /etc/sysconfig/docker"
158
- echo " OPTIONS=\"\$ OPTIONS --mtu=${FLANNEL_MTU} --bip=${FLANNEL_SUBNET} \" " | sudo tee -a ${DOCKER_CONF}
160
+ echo " OPTIONS=\"\$ OPTIONS --mtu=${FLANNEL_MTU} --bip=${FLANNEL_SUBNET} \" " | tee -a ${DOCKER_CONF}
159
161
ifconfig docker0 down
160
162
yum -y -q install bridge-utils && brctl delbr docker0 && service docker restart
161
163
;;
162
164
centos)
163
165
DOCKER_CONF=" /etc/sysconfig/docker"
164
- echo " OPTIONS=\"\$ OPTIONS --mtu=${FLANNEL_MTU} --bip=${FLANNEL_SUBNET} \" " | sudo tee -a ${DOCKER_CONF}
166
+ echo " OPTIONS=\"\$ OPTIONS --mtu=${FLANNEL_MTU} --bip=${FLANNEL_SUBNET} \" " | tee -a ${DOCKER_CONF}
165
167
if ! command_exists ifconfig; then
166
168
yum -y -q install net-tools
167
169
fi
@@ -170,7 +172,7 @@ start_k8s(){
170
172
;;
171
173
ubuntu|debian)
172
174
DOCKER_CONF=" /etc/default/docker"
173
- echo " DOCKER_OPTS=\"\$ DOCKER_OPTS --mtu=${FLANNEL_MTU} --bip=${FLANNEL_SUBNET} \" " | sudo tee -a ${DOCKER_CONF}
175
+ echo " DOCKER_OPTS=\"\$ DOCKER_OPTS --mtu=${FLANNEL_MTU} --bip=${FLANNEL_SUBNET} \" " | tee -a ${DOCKER_CONF}
174
176
ifconfig docker0 down
175
177
apt-get install bridge-utils
176
178
brctl delbr docker0
@@ -190,7 +192,7 @@ start_k8s(){
190
192
# sleep a little bit
191
193
sleep 5
192
194
193
- # Start kubelet & proxy, then start master components as pods
195
+ # Start kubelet and then start master components as pods
194
196
docker run \
195
197
--net=host \
196
198
--pid=host \
@@ -205,18 +207,16 @@ start_k8s(){
205
207
-v /var/lib/kubelet/:/var/lib/kubelet:rw \
206
208
gcr.io/google_containers/hyperkube:v${K8S_VERSION} \
207
209
/hyperkube kubelet \
208
- --v=2 --address=0.0.0.0 --enable-server \
209
- --config=/etc/kubernetes/manifests-multi \
210
- --cluster-dns=10.0.0.10 \
211
- --cluster-domain=cluster.local \
212
- --containerized
210
+ --address=0.0.0.0 \
211
+ --allow-privileged=true \
212
+ --enable-server \
213
+ --api-servers=http://localhost:8080 \
214
+ --config=/etc/kubernetes/manifests-multi \
215
+ --cluster-dns=10.0.0.10 \
216
+ --cluster-domain=cluster.local \
217
+ --containerized \
218
+ --v=2
213
219
214
- docker run \
215
- -d \
216
- --net=host \
217
- --privileged \
218
- gcr.io/google_containers/hyperkube:v${K8S_VERSION} \
219
- /hyperkube proxy --master=http://127.0.0.1:8080 --v=2
220
220
}
221
221
222
222
echo " Detecting your OS distro ..."
0 commit comments