provision-network-master.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # provision-network-master configures flannel on the master
  16. function provision-network-master {
  17. echo "Provisioning network on master"
  18. FLANNEL_ETCD_URL="http://${MASTER_IP}:4379"
  19. # Install etcd for flannel data
  20. if ! which etcd >/dev/null 2>&1; then
  21. dnf install -y etcd
  22. # Modify etcd configuration for flannel data
  23. cat <<EOF >/etc/etcd/etcd.conf
  24. ETCD_NAME=flannel
  25. ETCD_DATA_DIR="/var/lib/etcd/flannel.etcd"
  26. ETCD_LISTEN_PEER_URLS="http://${MASTER_IP}:4380"
  27. ETCD_LISTEN_CLIENT_URLS="http://${MASTER_IP}:4379"
  28. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${MASTER_IP}:4380"
  29. ETCD_INITIAL_CLUSTER="flannel=http://${MASTER_IP}:4380"
  30. ETCD_ADVERTISE_CLIENT_URLS="${FLANNEL_ETCD_URL}"
  31. EOF
  32. # fix the etcd boot failure issue
  33. sed -i '/^Restart/a RestartSec=10' /usr/lib/systemd/system/etcd.service
  34. systemctl daemon-reload
  35. # Enable and start etcd
  36. systemctl enable etcd
  37. systemctl start etcd
  38. fi
  39. # Install flannel for overlay
  40. if ! which flanneld >/dev/null 2>&1; then
  41. dnf install -y flannel
  42. cat <<EOF >/etc/flannel-config.json
  43. {
  44. "Network": "${CONTAINER_SUBNET}",
  45. "SubnetLen": 24,
  46. "Backend": {
  47. "Type": "udp",
  48. "Port": 8285
  49. }
  50. }
  51. EOF
  52. # Import default configuration into etcd for master setup
  53. etcdctl -C ${FLANNEL_ETCD_URL} set /coreos.com/network/config < /etc/flannel-config.json
  54. # Configure local daemon to speak to master
  55. NETWORK_CONF_PATH=/etc/sysconfig/network-scripts/
  56. if_to_edit=$( find ${NETWORK_CONF_PATH}ifcfg-* | xargs grep -l VAGRANT-BEGIN )
  57. NETWORK_IF_NAME=`echo ${if_to_edit} | awk -F- '{ print $3 }'`
  58. # needed for vsphere support
  59. # handle the case when no 'VAGRANT-BEGIN' comment was defined in network-scripts
  60. # set the NETWORK_IF_NAME to have a default value in such case
  61. if [[ -z "$NETWORK_IF_NAME" ]]; then
  62. NETWORK_IF_NAME=${DEFAULT_NETWORK_IF_NAME}
  63. fi
  64. cat <<EOF >/etc/sysconfig/flanneld
  65. FLANNEL_ETCD="${FLANNEL_ETCD_URL}"
  66. FLANNEL_ETCD_KEY="/coreos.com/network"
  67. FLANNEL_OPTIONS="-iface=${NETWORK_IF_NAME} --ip-masq"
  68. EOF
  69. # Start flannel
  70. systemctl enable flanneld
  71. systemctl start flanneld
  72. fi
  73. echo "Network configuration verified"
  74. }