configure-vm-aws.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. # Note: these functions override functions in the GCE configure-vm script
  16. # We include the GCE script first, and this one second.
  17. ensure-basic-networking() {
  18. :
  19. }
  20. ensure-packages() {
  21. apt-get-install curl
  22. # For reading kube_env.yaml
  23. apt-get-install python-yaml
  24. # TODO: Where to get safe_format_and_mount?
  25. mkdir -p /usr/share/google
  26. cd /usr/share/google
  27. download-or-bust "dc96f40fdc9a0815f099a51738587ef5a976f1da" https://raw.githubusercontent.com/GoogleCloudPlatform/compute-image-packages/82b75f314528b90485d5239ab5d5495cc22d775f/google-startup-scripts/usr/share/google/safe_format_and_mount
  28. chmod +x safe_format_and_mount
  29. }
  30. set-kube-env() {
  31. local kube_env_yaml="/etc/kubernetes/kube_env.yaml"
  32. # kube-env has all the environment variables we care about, in a flat yaml format
  33. eval "$(python -c '
  34. import pipes,sys,yaml
  35. for k,v in yaml.load(sys.stdin).iteritems():
  36. print("""readonly {var}={value}""".format(var = k, value = pipes.quote(str(v))))
  37. print("""export {var}""".format(var = k))
  38. ' < """${kube_env_yaml}""")"
  39. }
  40. remove-docker-artifacts() {
  41. :
  42. }
  43. # Finds the master PD device
  44. find-master-pd() {
  45. if ( grep "/mnt/master-pd" /proc/mounts ); then
  46. echo "Master PD already mounted; won't remount"
  47. MASTER_PD_DEVICE=""
  48. return
  49. fi
  50. echo "Waiting for master pd to be attached"
  51. attempt=0
  52. while true; do
  53. echo Attempt "$(($attempt+1))" to check for /dev/xvdb
  54. if [[ -e /dev/xvdb ]]; then
  55. echo "Found /dev/xvdb"
  56. MASTER_PD_DEVICE="/dev/xvdb"
  57. break
  58. fi
  59. attempt=$(($attempt+1))
  60. sleep 1
  61. done
  62. # Mount the master PD as early as possible
  63. echo "/dev/xvdb /mnt/master-pd ext4 noatime 0 0" >> /etc/fstab
  64. }
  65. fix-apt-sources() {
  66. :
  67. }
  68. salt-master-role() {
  69. cat <<EOF >/etc/salt/minion.d/grains.conf
  70. grains:
  71. roles:
  72. - kubernetes-master
  73. cloud: aws
  74. EOF
  75. # If the kubelet on the master is enabled, give it the same CIDR range
  76. # as a generic node.
  77. if [[ ! -z "${KUBELET_APISERVER:-}" ]] && [[ ! -z "${KUBELET_CERT:-}" ]] && [[ ! -z "${KUBELET_KEY:-}" ]]; then
  78. cat <<EOF >>/etc/salt/minion.d/grains.conf
  79. kubelet_api_servers: '${KUBELET_APISERVER}'
  80. cbr-cidr: 10.123.45.0/30
  81. EOF
  82. else
  83. # If the kubelet is running disconnected from a master, give it a fixed
  84. # CIDR range.
  85. cat <<EOF >>/etc/salt/minion.d/grains.conf
  86. cbr-cidr: ${MASTER_IP_RANGE}
  87. EOF
  88. fi
  89. env-to-grains "runtime_config"
  90. env-to-grains "kube_user"
  91. }
  92. salt-node-role() {
  93. cat <<EOF >/etc/salt/minion.d/grains.conf
  94. grains:
  95. roles:
  96. - kubernetes-pool
  97. cbr-cidr: 10.123.45.0/30
  98. cloud: aws
  99. api_servers: '${API_SERVERS}'
  100. EOF
  101. # We set the hostname_override to the full EC2 private dns name
  102. # we'd like to use EC2 instance-id, but currently the kubelet health-check assumes the name
  103. # is resolvable, although that check should be going away entirely (#7092)
  104. if [[ -z "${HOSTNAME_OVERRIDE:-}" ]]; then
  105. HOSTNAME_OVERRIDE=`curl --silent curl http://169.254.169.254/2007-01-19/meta-data/local-hostname`
  106. fi
  107. env-to-grains "hostname_override"
  108. }
  109. function run-user-script() {
  110. # TODO(justinsb): Support user scripts on AWS
  111. # AWS doesn't have as rich a metadata service as GCE does
  112. # Maybe specify an env var that is the path to a script?
  113. :
  114. }