provision-node.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # Copyright 2014 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. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. # Set the host name explicitly
  19. # See: https://github.com/mitchellh/vagrant/issues/2430
  20. hostnamectl set-hostname ${NODE_NAME}
  21. if_to_edit=""
  22. if [[ "$(grep 'VERSION_ID' /etc/os-release)" =~ ^VERSION_ID=23 ]]; then
  23. # Disable network interface being managed by Network Manager (needed for Fedora 21+)
  24. NETWORK_CONF_PATH=/etc/sysconfig/network-scripts/
  25. if_to_edit=$( find ${NETWORK_CONF_PATH}ifcfg-* | xargs grep -l VAGRANT-BEGIN )
  26. for if_conf in ${if_to_edit}; do
  27. grep -q ^NM_CONTROLLED= ${if_conf} || echo 'NM_CONTROLLED=no' >> ${if_conf}
  28. sed -i 's/#^NM_CONTROLLED=.*/NM_CONTROLLED=no/' ${if_conf}
  29. done;
  30. systemctl restart network
  31. fi
  32. # needed for vsphere support
  33. # handle the case when no 'VAGRANT-BEGIN' comment was defined in network-scripts
  34. # set the NETWORK_IF_NAME to have a default value in such case
  35. NETWORK_IF_NAME=`echo ${if_to_edit} | awk -F- '{ print $3 }'`
  36. if [[ -z "$NETWORK_IF_NAME" ]]; then
  37. NETWORK_IF_NAME=${DEFAULT_NETWORK_IF_NAME}
  38. fi
  39. # Setup hosts file to support ping by hostname to master
  40. if [ ! "$(cat /etc/hosts | grep $MASTER_NAME)" ]; then
  41. echo "Adding $MASTER_NAME to hosts file"
  42. echo "$MASTER_IP $MASTER_NAME" >> /etc/hosts
  43. fi
  44. echo "$NODE_IP $NODE_NAME" >> /etc/hosts
  45. # Setup hosts file to support ping by hostname to each node in the cluster
  46. for (( i=0; i<${#NODE_NAMES[@]}; i++)); do
  47. node=${NODE_NAMES[$i]}
  48. ip=${NODE_IPS[$i]}
  49. if [ ! "$(cat /etc/hosts | grep $node)" ]; then
  50. echo "Adding $node to hosts file"
  51. echo "$ip $node" >> /etc/hosts
  52. fi
  53. done
  54. enable-accounting
  55. prepare-package-manager
  56. # Configure network
  57. if [ "${NETWORK_PROVIDER}" != "kubenet" ]; then
  58. provision-network-node
  59. fi
  60. write-salt-config kubernetes-pool
  61. # Generate kubelet and kube-proxy auth file(kubeconfig) if there is not an existing one
  62. known_kubeconfig_file="/srv/salt-overlay/salt/kubelet/kubeconfig"
  63. if [[ ! -f "${known_kubeconfig_file}" ]]; then
  64. create-salt-kubelet-auth
  65. create-salt-kubeproxy-auth
  66. else
  67. # stop kubelet, let salt start it later
  68. systemctl stop kubelet
  69. fi
  70. install-salt
  71. add-volume-support
  72. run-salt
  73. dnf install -y socat ethtool
  74. dnf update -y docker