Skip to content

Commit

Permalink
Merge pull request kubernetes#492 from reAsOn2010/bugfix-docker-flann…
Browse files Browse the repository at this point in the history
…el-opt

fix bug: docker daemon starting with wrong opt after flanneld restarted.
  • Loading branch information
ddysher authored and keontang committed Feb 7, 2017
2 parents a633af0 + aa0ed5b commit db826af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
65 changes: 36 additions & 29 deletions cluster/caicloud/config-components.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,41 @@ EOF
fi
}

# Create docker options with flanneld environment
#
# Output:
# A file with docker configs under ~/kube/configs/docker
#
# Assumed vars:
# REGISTRY_MIRROR
function create-docker-opts {
cat <<EOF > ~/kube/configs/docker
#!/bin/sh
attempt=0
while true; do
echo "Attemp \$((\$attempt+1)) to check for subnet.env set by flannel"
if [ -f "/run/flannel/subnet.env" ] && \\
grep -q "FLANNEL_SUBNET" /run/flannel/subnet.env && \\
grep -q "FLANNEL_MTU" /run/flannel/subnet.env ; then
break
else
if (( attempt > 60 )); then
echo "timeout waiting for subnet.env from flannel"
exit 2
fi
attempt=\$((attempt+1))
sleep 3
fi
done
. /run/flannel/subnet.env
DOCKER_OPTS="-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock \\
--bip=\${FLANNEL_SUBNET} --mtu=\${FLANNEL_MTU} \\
--registry-mirror=${REGISTRY_MIRROR} "
EOF
}

# Config flanneld options in etcd. The method is called from master, and
# master should have etcdctl available.
#
Expand Down Expand Up @@ -259,32 +294,8 @@ function config-etcd-flanneld {
done
}

# Configure docker network settings to use flannel overlay network.
#
# Input:
# $1 File to write docker config, e.g. /etc/default/docker, /etc/sysconfig/docker.
#
# Assumed vars:
# REGISTRY_MIRROR
# Safely restart docker daemon
function restart-docker {
# Wait for /run/flannel/subnet.env to be ready.
attempt=0
while true; do
echo "Attempt $(($attempt+1)) to check for subnet.env set by flannel"
if [[ -f /run/flannel/subnet.env ]] && \
grep -q "FLANNEL_SUBNET" /run/flannel/subnet.env && \
grep -q "FLANNEL_MTU" /run/flannel/subnet.env ; then
break
else
if (( attempt > 60 )); then
echo "timeout waiting for subnet.env from flannel"
exit 2
fi
attempt=$((attempt+1))
sleep 3
fi
done

# In order for docker to correctly use flannel setting, we first stop docker,
# flush nat table, delete docker0 and then start docker. Missing any one of
# the steps may result in wrong iptable rules, see:
Expand All @@ -294,9 +305,5 @@ function restart-docker {
sudo ip link set dev docker0 down
sudo brctl delbr docker0

source /run/flannel/subnet.env
echo DOCKER_OPTS=\"-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock \
--bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} \
--registry-mirror=${REGISTRY_MIRROR} \" > ${1}
sudo service docker start
}
6 changes: 4 additions & 2 deletions cluster/caicloud/trusty/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function send-master-files {
echo "create-kubelet-opts 'master'"
echo "create-kube-proxy-opts 'master'"
echo "create-flanneld-opts 'master'"
echo "create-docker-opts"
# Create the system directories used to hold the final data.
echo "sudo mkdir -p /opt/bin"
echo "sudo mkdir -p /etc/kubernetes"
Expand Down Expand Up @@ -137,7 +138,7 @@ function send-master-files {
# After starting etcd, configure flannel options.
echo "config-etcd-flanneld"
# After starting flannel, configure docker network to use flannel overlay.
echo "restart-docker /etc/default/docker"
echo "restart-docker"
# Note: After using iptables mode, we need to change flannel to use --ip-masq, but
# it won't take effect after docker restart, we have to restart flannel again.
echo "sudo service flanneld restart"
Expand Down Expand Up @@ -267,6 +268,7 @@ function send-node-files-internal {
echo "create-kubelet-opts 'node' ${3}"
echo "create-kube-proxy-opts 'node'"
echo "create-flanneld-opts 'node'"
echo "create-docker-opts"
# Create the system directories used to hold the final data.
echo "sudo mkdir -p /opt/bin"
echo "sudo mkdir -p /etc/kubernetes"
Expand Down Expand Up @@ -295,7 +297,7 @@ function send-node-files-internal {
# start upon flannel start.
echo "sudo service flanneld start"
# After starting flannel, configure docker network to use flannel overlay.
echo "restart-docker /etc/default/docker"
echo "restart-docker"
# Note: After using iptables mode, we need to change flannel to use --ip-masq, but
# it won't take effect after docker restart, we have to restart flannel again.
echo "sudo service flanneld restart"
Expand Down

0 comments on commit db826af

Please sign in to comment.