setup_host.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env bash
  2. # Copyright 2016 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. # Script used to configure node e2e test hosts from gce base images.
  16. # DISCLAIMER: This script is not actively tested or maintained. No guarantees that this will work
  17. # on any host environment. Contributions encouraged! Send PRs to pwittrock (github.com).
  18. #
  19. # At some point has successfully configured the following distros:
  20. # - ubuntu trusty
  21. # - containervm (no-op)
  22. # - rhel 7
  23. # - centos 7
  24. # - debian jessie
  25. # RHEL os detection
  26. cat /etc/*-release | grep "ID=\"rhel\""
  27. OS_RHEL=$?
  28. # On a systemd environment, enable cpu and memory accounting for all processes by default.
  29. if [ -d /etc/systemd ]; then
  30. cat <<EOF >kubernetes-accounting.conf
  31. [Manager]
  32. DefaultCPUAccounting=yes
  33. DefaultMemoryAccounting=yes
  34. EOF
  35. sudo mkdir -p /etc/systemd/system.conf.d/
  36. sudo cp kubernetes-accounting.conf /etc/systemd/system.conf.d
  37. sudo systemctl daemon-reload
  38. fi
  39. # For coreos, disable updates
  40. if sudo systemctl status update-engine &>/dev/null; then
  41. sudo systemctl mask update-engine locksmithd
  42. fi
  43. # Fixup sudoers require tty
  44. if ! sudo grep -q "# Defaults requiretty" /etc/sudoers; then
  45. sudo sed -i 's/Defaults requiretty/# Defaults requiretty/' /etc/sudoers
  46. fi
  47. # Install nsenter for ubuntu images
  48. if cat /etc/*-release | grep "ID=ubuntu"; then
  49. if ! which nsenter > /dev/null; then
  50. echo "Do not find nsenter. Install it."
  51. NSENTER_BUILD_DIR=$(mktemp -d /tmp/nsenter-build-XXXXXX)
  52. cd "$NSENTER_BUILD_DIR" || exit 1
  53. curl https://www.kernel.org/pub/linux/utils/util-linux/v2.31/util-linux-2.31.tar.gz | tar -zxf-
  54. sudo apt-get update
  55. sudo apt-get --yes install make
  56. sudo apt-get --yes install gcc
  57. cd util-linux-2.31 || exit 1
  58. ./configure --without-ncurses
  59. make nsenter
  60. sudo cp nsenter /usr/local/bin
  61. rm -rf "$NSENTER_BUILD_DIR"
  62. fi
  63. fi
  64. # Install docker
  65. if ! hash docker 2>/dev/null; then
  66. # RHEL platforms should always install from RHEL repository
  67. # This will install the latest supported stable docker platform on RHEL
  68. if [ $OS_RHEL -eq 0 ]; then
  69. sudo yum install -y docker-latest
  70. sudo groupadd docker
  71. sudo systemctl enable docker-latest.service
  72. sudo systemctl start docker-latest.service
  73. else
  74. curl -fsSL https://get.docker.com/ | sh
  75. sudo service docker start
  76. sudo systemctl enable docker.service
  77. fi
  78. fi
  79. # Allow jenkins access to docker
  80. id jenkins || sudo useradd jenkins -m
  81. sudo usermod -a -G docker jenkins
  82. # install lxc
  83. if ! cat /etc/*-release | grep "ID=debian"; then
  84. hash apt-get 2>/dev/null
  85. if [ $? -ne 1 ]; then
  86. sudo apt-get install lxc -y
  87. lxc-checkconfig
  88. sudo sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="\1 cgroup_enable=memory"/' /etc/default/grub
  89. sudo update-grub
  90. fi
  91. fi
  92. # delete init kubelet from containervm so that is doesn't startup
  93. if [ -f /etc/init.d/kubelet ]; then
  94. sudo rm /etc/init.d/kubelet
  95. fi