get-kube.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # Bring up a Kubernetes cluster.
  16. # Usage:
  17. # wget -q -O - https://get.k8s.io | bash
  18. # or
  19. # curl -sS https://get.k8s.io | bash
  20. #
  21. # Advanced options
  22. # Set KUBERNETES_PROVIDER to choose between different providers:
  23. # Google Compute Engine [default]
  24. # * export KUBERNETES_PROVIDER=gce; wget -q -O - https://get.k8s.io | bash
  25. # Google Container Engine
  26. # * export KUBERNETES_PROVIDER=gke; wget -q -O - https://get.k8s.io | bash
  27. # Amazon EC2
  28. # * export KUBERNETES_PROVIDER=aws; wget -q -O - https://get.k8s.io | bash
  29. # Libvirt (with CoreOS as a guest operating system)
  30. # * export KUBERNETES_PROVIDER=libvirt-coreos; wget -q -O - https://get.k8s.io | bash
  31. # Microsoft Azure
  32. # * export KUBERNETES_PROVIDER=azure-legacy; wget -q -O - https://get.k8s.io | bash
  33. # Vagrant (local virtual machines)
  34. # * export KUBERNETES_PROVIDER=vagrant; wget -q -O - https://get.k8s.io | bash
  35. # VMWare VSphere
  36. # * export KUBERNETES_PROVIDER=vsphere; wget -q -O - https://get.k8s.io | bash
  37. # VMWare Photon Controller
  38. # * export KUBERNETES_PROVIDER=photon-controller; wget -q -O - https://get.k8s.io | bash
  39. # Rackspace
  40. # * export KUBERNETES_PROVIDER=rackspace; wget -q -O - https://get.k8s.io | bash
  41. # OpenStack-Heat
  42. # * export KUBERNETES_PROVIDER=openstack-heat; wget -q -O - https://get.k8s.io | bash
  43. #
  44. # Set KUBERNETES_SKIP_DOWNLOAD to non-empty to skip downloading a release.
  45. # Set KUBERNETES_SKIP_CONFIRM to skip the installation confirmation prompt.
  46. # Set KUBERNETES_RELEASE to the release you want to use (e.g. 'v1.2.0'). See https://github.com/kubernetes/kubernetes/releases for release options
  47. set -o errexit
  48. set -o nounset
  49. set -o pipefail
  50. function create_cluster {
  51. echo "Creating a kubernetes on ${KUBERNETES_PROVIDER:-gce}..."
  52. (
  53. cd kubernetes
  54. ./cluster/kube-up.sh
  55. echo "Kubernetes binaries at ${PWD}/cluster/"
  56. if [[ ":$PATH:" != *":${PWD}/cluster:"* ]]; then
  57. echo "You may want to add this directory to your PATH in \$HOME/.profile"
  58. fi
  59. echo "Installation successful!"
  60. )
  61. }
  62. if [[ "${KUBERNETES_SKIP_DOWNLOAD-}" ]]; then
  63. create_cluster
  64. exit 0
  65. fi
  66. if [[ -d "./kubernetes" ]]; then
  67. if [[ -n "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
  68. echo "'kubernetes' directory already exist. Should we skip download step and start to create cluster based on it? [Y]/n"
  69. read confirm
  70. if [[ "$confirm" == "y" ]]; then
  71. echo "Skipping download step."
  72. create_cluster
  73. exit 0
  74. fi
  75. fi
  76. fi
  77. function get_latest_version_number {
  78. local -r latest_url="https://storage.googleapis.com/kubernetes-release/release/stable.txt"
  79. if [[ $(which wget) ]]; then
  80. wget -qO- ${latest_url}
  81. elif [[ $(which curl) ]]; then
  82. curl -Ss ${latest_url}
  83. else
  84. echo "Couldn't find curl or wget. Bailing out." >&2
  85. exit 4
  86. fi
  87. }
  88. release=${KUBERNETES_RELEASE:-$(get_latest_version_number)}
  89. release_url=https://storage.googleapis.com/kubernetes-release/release/${release}/kubernetes.tar.gz
  90. uname=$(uname)
  91. if [[ "${uname}" == "Darwin" ]]; then
  92. platform="darwin"
  93. elif [[ "${uname}" == "Linux" ]]; then
  94. platform="linux"
  95. else
  96. echo "Unknown, unsupported platform: (${uname})."
  97. echo "Supported platforms: Linux, Darwin."
  98. echo "Bailing out."
  99. exit 2
  100. fi
  101. machine=$(uname -m)
  102. if [[ "${machine}" == "x86_64" ]]; then
  103. arch="amd64"
  104. elif [[ "${machine}" == "i686" ]]; then
  105. arch="386"
  106. elif [[ "${machine}" == "arm*" ]]; then
  107. arch="arm"
  108. elif [[ "${machine}" == "s390x*" ]]; then
  109. arch="s390x"
  110. elif [[ "${machine}" == "ppc64le" ]]; then
  111. arch="ppc64le"
  112. else
  113. echo "Unknown, unsupported architecture (${machine})."
  114. echo "Supported architectures x86_64, i686, arm, s390x, ppc64le."
  115. echo "Bailing out."
  116. exit 3
  117. fi
  118. file=kubernetes.tar.gz
  119. echo "Downloading kubernetes release ${release} to ${PWD}/kubernetes.tar.gz"
  120. if [[ -n "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
  121. echo "Is this ok? [Y]/n"
  122. read confirm
  123. if [[ "$confirm" == "n" ]]; then
  124. echo "Aborting."
  125. exit 0
  126. fi
  127. fi
  128. if [[ $(which wget) ]]; then
  129. wget -N ${release_url}
  130. elif [[ $(which curl) ]]; then
  131. curl -L -z ${file} ${release_url} -o ${file}
  132. else
  133. echo "Couldn't find curl or wget. Bailing out."
  134. exit 1
  135. fi
  136. echo "Unpacking kubernetes release ${release}"
  137. tar -xzf ${file}
  138. create_cluster