provision-network-node.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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-node configures flannel on the node
  16. function provision-network-node {
  17. echo "Provisioning network on node"
  18. FLANNEL_ETCD_URL="http://${MASTER_IP}:4379"
  19. # Install flannel for overlay
  20. if ! which flanneld >/dev/null 2>&1; then
  21. dnf install -y flannel
  22. # Configure local daemon to speak to master
  23. NETWORK_CONF_PATH=/etc/sysconfig/network-scripts/
  24. if_to_edit=$( find ${NETWORK_CONF_PATH}ifcfg-* | xargs grep -l VAGRANT-BEGIN )
  25. NETWORK_IF_NAME=`echo ${if_to_edit} | awk -F- '{ print $3 }'`
  26. # needed for vsphere support
  27. # handle the case when no 'VAGRANT-BEGIN' comment was defined in network-scripts
  28. # set the NETWORK_IF_NAME to have a default value in such case
  29. if [[ -z "$NETWORK_IF_NAME" ]]; then
  30. NETWORK_IF_NAME=${DEFAULT_NETWORK_IF_NAME}
  31. fi
  32. cat <<EOF >/etc/sysconfig/flanneld
  33. FLANNEL_ETCD="${FLANNEL_ETCD_URL}"
  34. FLANNEL_ETCD_KEY="/coreos.com/network"
  35. FLANNEL_OPTIONS="-iface=${NETWORK_IF_NAME} --ip-masq"
  36. EOF
  37. # Start flannel
  38. systemctl enable flanneld
  39. systemctl start flanneld
  40. fi
  41. echo "Network configuration verified"
  42. }