2016-10-26 01:23:59 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-12-23 00:00:35 +00:00
|
|
|
|
2016-06-03 00:25:58 +00:00
|
|
|
# Copyright 2014 The Kubernetes Authors.
|
2014-12-23 00:00:35 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
# Bring up a Kubernetes cluster.
|
|
|
|
# Usage:
|
2015-03-22 05:50:29 +00:00
|
|
|
# wget -q -O - https://get.k8s.io | bash
|
2014-12-23 00:00:35 +00:00
|
|
|
# or
|
2016-11-04 18:48:15 +00:00
|
|
|
# curl -fsSL https://get.k8s.io | bash
|
2014-12-23 00:00:35 +00:00
|
|
|
#
|
|
|
|
# Advanced options
|
|
|
|
# Set KUBERNETES_PROVIDER to choose between different providers:
|
|
|
|
# Google Compute Engine [default]
|
2015-03-22 05:50:29 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=gce; wget -q -O - https://get.k8s.io | bash
|
2015-01-28 06:08:22 +00:00
|
|
|
# Google Container Engine
|
2015-03-22 05:50:29 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=gke; wget -q -O - https://get.k8s.io | bash
|
2014-12-23 00:00:35 +00:00
|
|
|
# Amazon EC2
|
2015-03-22 05:50:29 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=aws; wget -q -O - https://get.k8s.io | bash
|
2015-11-16 16:14:11 +00:00
|
|
|
# Libvirt (with CoreOS as a guest operating system)
|
|
|
|
# * export KUBERNETES_PROVIDER=libvirt-coreos; wget -q -O - https://get.k8s.io | bash
|
2016-01-12 03:11:52 +00:00
|
|
|
# Microsoft Azure
|
2016-01-26 21:46:02 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=azure-legacy; wget -q -O - https://get.k8s.io | bash
|
2014-12-23 00:00:35 +00:00
|
|
|
# Vagrant (local virtual machines)
|
2015-03-22 05:50:29 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=vagrant; wget -q -O - https://get.k8s.io | bash
|
2014-12-23 00:00:35 +00:00
|
|
|
# VMWare VSphere
|
2015-03-22 05:50:29 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=vsphere; wget -q -O - https://get.k8s.io | bash
|
2016-03-08 19:25:41 +00:00
|
|
|
# VMWare Photon Controller
|
|
|
|
# * export KUBERNETES_PROVIDER=photon-controller; wget -q -O - https://get.k8s.io | bash
|
2014-12-23 00:00:35 +00:00
|
|
|
# Rackspace
|
2015-03-22 05:50:29 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=rackspace; wget -q -O - https://get.k8s.io | bash
|
2016-05-10 05:25:29 +00:00
|
|
|
# OpenStack-Heat
|
2016-04-25 04:59:12 +00:00
|
|
|
# * export KUBERNETES_PROVIDER=openstack-heat; wget -q -O - https://get.k8s.io | bash
|
2015-01-06 21:08:31 +00:00
|
|
|
#
|
2016-09-28 21:50:01 +00:00
|
|
|
# Set KUBERNETES_RELEASE to choose a specific release instead of the current
|
|
|
|
# stable release, (e.g. 'v1.3.7').
|
|
|
|
# See https://github.com/kubernetes/kubernetes/releases for release options.
|
|
|
|
# Set KUBERNETES_RELEASE_URL to choose where to download binaries from.
|
|
|
|
# (Defaults to https://storage.googleapis.com/kubernetes-release/release).
|
|
|
|
#
|
|
|
|
# Set KUBERNETES_SERVER_ARCH to choose the server (Kubernetes cluster)
|
|
|
|
# architecture to download:
|
|
|
|
# * amd64 [default]
|
|
|
|
# * arm
|
|
|
|
# * arm64
|
|
|
|
#
|
|
|
|
# Set KUBERNETES_SKIP_DOWNLOAD to skip downloading a release.
|
2015-01-06 21:08:31 +00:00
|
|
|
# Set KUBERNETES_SKIP_CONFIRM to skip the installation confirmation prompt.
|
2016-09-28 21:50:01 +00:00
|
|
|
# Set KUBERNETES_SKIP_CREATE_CLUSTER to skip starting a cluster.
|
|
|
|
|
2014-12-23 00:00:35 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
|
2016-09-28 21:50:01 +00:00
|
|
|
KUBERNETES_RELEASE_URL="${KUBERNETES_RELEASE_URL:-https://storage.googleapis.com/kubernetes-release/release}"
|
|
|
|
|
|
|
|
# Use the script from inside the Kubernetes tarball to fetch the client and
|
|
|
|
# server binaries (if not included in kubernetes.tar.gz).
|
|
|
|
function download_kube_binaries {
|
|
|
|
(
|
|
|
|
cd kubernetes
|
|
|
|
if [[ -x ./cluster/get-kube-binaries.sh ]]; then
|
|
|
|
./cluster/get-kube-binaries.sh
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:08:31 +00:00
|
|
|
function create_cluster {
|
2016-10-18 20:09:02 +00:00
|
|
|
if [[ -n "${KUBERNETES_SKIP_CREATE_CLUSTER-}" ]]; then
|
2016-09-28 21:50:01 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2015-01-06 21:08:31 +00:00
|
|
|
echo "Creating a kubernetes on ${KUBERNETES_PROVIDER:-gce}..."
|
|
|
|
(
|
|
|
|
cd kubernetes
|
|
|
|
./cluster/kube-up.sh
|
2015-04-24 21:31:21 +00:00
|
|
|
echo "Kubernetes binaries at ${PWD}/cluster/"
|
2015-05-26 12:27:36 +00:00
|
|
|
if [[ ":$PATH:" != *":${PWD}/cluster:"* ]]; then
|
|
|
|
echo "You may want to add this directory to your PATH in \$HOME/.profile"
|
|
|
|
fi
|
2015-01-06 21:08:31 +00:00
|
|
|
|
|
|
|
echo "Installation successful!"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-09-28 21:50:01 +00:00
|
|
|
if [[ -n "${KUBERNETES_SKIP_DOWNLOAD-}" ]]; then
|
2015-01-06 21:08:31 +00:00
|
|
|
create_cluster
|
2015-01-06 21:08:31 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2016-05-11 13:19:18 +00:00
|
|
|
if [[ -d "./kubernetes" ]]; then
|
2016-09-28 21:50:01 +00:00
|
|
|
if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
|
2016-05-11 13:19:18 +00:00
|
|
|
echo "'kubernetes' directory already exist. Should we skip download step and start to create cluster based on it? [Y]/n"
|
|
|
|
read confirm
|
2016-09-28 21:50:01 +00:00
|
|
|
if [[ ! "${confirm}" =~ ^[nN]$ ]]; then
|
2016-05-11 13:19:18 +00:00
|
|
|
echo "Skipping download step."
|
|
|
|
create_cluster
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-03-17 21:36:12 +00:00
|
|
|
function get_latest_version_number {
|
2015-03-26 22:15:45 +00:00
|
|
|
local -r latest_url="https://storage.googleapis.com/kubernetes-release/release/stable.txt"
|
2015-03-17 21:36:12 +00:00
|
|
|
if [[ $(which wget) ]]; then
|
2016-10-26 01:23:59 +00:00
|
|
|
wget -qO- "${latest_url}"
|
2015-03-17 21:36:12 +00:00
|
|
|
elif [[ $(which curl) ]]; then
|
2016-11-04 18:48:15 +00:00
|
|
|
curl -sSfL --retry 3 --keepalive-time 2 "${latest_url}"
|
2015-05-26 12:27:36 +00:00
|
|
|
else
|
2016-05-09 19:50:50 +00:00
|
|
|
echo "Couldn't find curl or wget. Bailing out." >&2
|
2015-05-26 12:27:36 +00:00
|
|
|
exit 4
|
2015-03-17 21:36:12 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-09-28 21:50:01 +00:00
|
|
|
# TODO: remove client checks once kubernetes.tar.gz no longer includes client
|
|
|
|
# binaries by default.
|
|
|
|
kernel=$(uname -s)
|
|
|
|
case "${kernel}" in
|
|
|
|
Darwin)
|
|
|
|
platform="darwin"
|
|
|
|
;;
|
|
|
|
Linux)
|
|
|
|
platform="linux"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown, unsupported platform: ${kernel}." >&2
|
|
|
|
echo "Supported platforms: Linux, Darwin." >&2
|
|
|
|
echo "Bailing out." >&2
|
|
|
|
exit 2
|
|
|
|
esac
|
2014-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
machine=$(uname -m)
|
2016-09-28 21:50:01 +00:00
|
|
|
case "${machine}" in
|
|
|
|
x86_64*|i?86_64*|amd64*)
|
|
|
|
arch="amd64"
|
|
|
|
;;
|
|
|
|
aarch64*|arm64*)
|
|
|
|
arch="arm64"
|
|
|
|
;;
|
|
|
|
arm*)
|
|
|
|
arch="arm"
|
|
|
|
;;
|
|
|
|
i?86*)
|
|
|
|
arch="386"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown, unsupported architecture (${machine})." >&2
|
|
|
|
echo "Supported architectures x86_64, i686, arm, arm64." >&2
|
|
|
|
echo "Bailing out." >&2
|
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
esac
|
2014-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
file=kubernetes.tar.gz
|
2016-10-26 01:23:59 +00:00
|
|
|
release=${KUBERNETES_RELEASE:-$(get_latest_version_number)}
|
|
|
|
release_url="${KUBERNETES_RELEASE_URL}/${release}/${file}"
|
|
|
|
|
|
|
|
need_download=true
|
|
|
|
if [[ -r "${PWD}/${file}" ]]; then
|
|
|
|
downloaded_version=$(tar -xzOf "${PWD}/${file}" kubernetes/version 2>/dev/null || true)
|
|
|
|
echo "Found preexisting ${file}, release ${downloaded_version}"
|
|
|
|
if [[ "${downloaded_version}" == "${release}" ]]; then
|
|
|
|
echo "Using preexisting kubernetes.tar.gz"
|
|
|
|
need_download=false
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if "${need_download}"; then
|
|
|
|
echo "Downloading kubernetes release ${release}"
|
|
|
|
echo " from ${release_url}"
|
|
|
|
echo " to ${PWD}/${file}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e "${PWD}/kubernetes" ]]; then
|
|
|
|
# Let's try not to accidentally nuke something that isn't a kubernetes
|
|
|
|
# release dir.
|
|
|
|
if [[ ! -f "${PWD}/kubernetes/version" ]]; then
|
|
|
|
echo "${PWD}/kubernetes exists but does not look like a Kubernetes release."
|
|
|
|
echo "Aborting!"
|
|
|
|
exit 5
|
|
|
|
fi
|
|
|
|
echo "Will also delete preexisting 'kubernetes' directory."
|
|
|
|
fi
|
2014-12-23 00:00:35 +00:00
|
|
|
|
2016-09-28 21:50:01 +00:00
|
|
|
if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
|
2015-01-06 21:08:31 +00:00
|
|
|
echo "Is this ok? [Y]/n"
|
|
|
|
read confirm
|
2016-09-28 21:50:01 +00:00
|
|
|
if [[ "${confirm}" =~ ^[nN]$ ]]; then
|
2015-01-06 21:08:31 +00:00
|
|
|
echo "Aborting."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-10-26 01:23:59 +00:00
|
|
|
if "${need_download}"; then
|
|
|
|
if [[ $(which curl) ]]; then
|
2016-11-04 18:48:15 +00:00
|
|
|
curl -fL --retry 3 --keepalive-time 2 "${release_url}" -o "${file}"
|
2016-10-26 01:23:59 +00:00
|
|
|
elif [[ $(which wget) ]]; then
|
|
|
|
wget "${release_url}"
|
|
|
|
else
|
|
|
|
echo "Couldn't find curl or wget. Bailing out."
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-12-23 00:00:35 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Unpacking kubernetes release ${release}"
|
2016-10-26 01:23:59 +00:00
|
|
|
rm -rf "${PWD}/kubernetes"
|
2014-12-23 00:00:35 +00:00
|
|
|
tar -xzf ${file}
|
|
|
|
|
2016-09-28 21:50:01 +00:00
|
|
|
download_kube_binaries
|
2015-01-06 21:08:31 +00:00
|
|
|
create_cluster
|