mirror of https://github.com/k3s-io/k3s
Implement a build and deploy script to turn up/down federation.
Also, wrap the script around a Makefile. And also provide a sample config file to describe clusters. The build script implements the following things: 1. Generates the required configs. 2. Builds the hyperkube binary and the corresponding docker image. 3. Pushes the image to a specified repository. 4. Pulls the federation installer docker images. 5. Builds the Kubernetes clusters described the config.json file. 6. Pushes the federation components to one of the Kubernetes clusters built in the previous step. 7. Also turns down the federation components and the Kubernetes clusters.pull/6/head
parent
ea69570f61
commit
c4d4aff0d3
|
@ -0,0 +1,26 @@
|
|||
# Copyright 2016 The Kubernetes Authors.
|
||||
#
|
||||
# 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.
|
||||
|
||||
DBG_MAKEFILE ?=
|
||||
ifeq ($(DBG_MAKEFILE),1)
|
||||
$(warning ***** starting makefile for goal(s) "$(MAKECMDGOALS)")
|
||||
$(warning ***** $(shell date))
|
||||
else
|
||||
# If we're not debugging the Makefile, don't echo recipes.
|
||||
MAKEFLAGS += -s
|
||||
endif
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
./build.sh $(do)
|
|
@ -0,0 +1,170 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# This script will build the hyperkube image and push it to the repository
|
||||
# referred to by KUBE_REGISTRY. The image will be given a version tag with
|
||||
# the value from KUBE_VERSION. It also turns up/turns down Kubernetes
|
||||
# clusters and federation components using the built hyperkube image.
|
||||
# e.g. run as:
|
||||
# KUBE_REGISTRY=localhost:5000/anushku \
|
||||
# KUBE_VERSION=1.3.0-dev ./build.sh
|
||||
#
|
||||
# will deploy the components using
|
||||
# localhost:5000/anushku/hyperkube-amd64:1.3.0-dev image.
|
||||
|
||||
# TODO(madhusudancs): Separate the dev functions from the deployment
|
||||
# functions. A lot of code here is to make this work in dev environments.
|
||||
# The script that we ship to the users as part of a release should be
|
||||
# much simpler (about 80% of the code here could be removed for non-dev
|
||||
# environments).
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
CUR_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
|
||||
source "${KUBE_ROOT}/build/util.sh"
|
||||
source "${KUBE_ROOT}/build/common.sh"
|
||||
|
||||
readonly ACTION="${1:-gen}"
|
||||
|
||||
readonly TMP_DIR="$(mktemp -d)"
|
||||
|
||||
readonly FEDERATION_OUTPUT_ROOT="${LOCAL_OUTPUT_ROOT}/federation"
|
||||
|
||||
readonly KUBE_ANYWHERE_FEDERATION_IMAGE="gcr.io/madhusudancs-containers/kubernetes-anywhere-federation"
|
||||
readonly KUBE_ANYWHERE_FEDERATION_VERSION="v0.9.0"
|
||||
|
||||
readonly KUBE_ANYWHERE_FEDERATION_CHARTS_IMAGE="gcr.io/madhusudancs-containers/federation-charts"
|
||||
readonly KUBE_ANYWHERE_FEDERATION_CHARTS_VERSION="v0.9.0"
|
||||
|
||||
KUBE_PROJECT="madhusudancs-k8s"
|
||||
KUBE_REGISTRY="${KUBE_REGISTRY:-gcr.io/${KUBE_PROJECT}}"
|
||||
KUBE_VERSION="${KUBE_VERSION:-$(kube::release::semantic_image_tag_version)}"
|
||||
|
||||
|
||||
function cleanup {
|
||||
rm -rf "${TMP_DIR}"
|
||||
cd "${CUR_ROOT}"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
function dirty_sha() {
|
||||
local -r index="${KUBE_ROOT}/.git/index"
|
||||
local -r objects_dir="${KUBE_ROOT}/.git/objects"
|
||||
|
||||
local -r tmp_dir="${TMP_DIR}/.git"
|
||||
local -r tmp_index="${tmp_dir}/index"
|
||||
local -r tmp_objects_dir="${tmp_dir}/objects"
|
||||
|
||||
mkdir -p "${tmp_objects_dir}"
|
||||
cp "${index}" "${tmp_index}"
|
||||
|
||||
local -r files=$(git ls-files -m -o -d --exclude-standard)
|
||||
GIT_INDEX_FILE="${tmp_index}" git add ${files}
|
||||
GIT_ALTERNATE_OBJECT_DIRECTORIES="${objects_dir}" GIT_OBJECT_DIRECTORY="${tmp_objects_dir}" GIT_INDEX_FILE="${tmp_index}" git write-tree
|
||||
}
|
||||
|
||||
function update_config() {
|
||||
local -r q="${1:-}"
|
||||
local -r cfile="${2:-}"
|
||||
local -r bname="$(basename ${cfile})"
|
||||
|
||||
jq "${q}" "${cfile}" > "${TMP_DIR}/${bname}"
|
||||
mv "${TMP_DIR}/${bname}" "${cfile}"
|
||||
}
|
||||
|
||||
function build() {
|
||||
kube::build::verify_prereqs
|
||||
kube::build::build_image
|
||||
kube::build::run_build_command make WHAT=cmd/hyperkube
|
||||
|
||||
BASEIMAGE="ubuntu:16.04" \
|
||||
REGISTRY="${KUBE_REGISTRY}" \
|
||||
VERSION="${KUBE_VERSION}" \
|
||||
make -C "${KUBE_ROOT}/cluster/images/hyperkube" build
|
||||
}
|
||||
|
||||
function push() {
|
||||
gcloud docker push "${KUBE_REGISTRY}/hyperkube-amd64:${KUBE_VERSION}"
|
||||
}
|
||||
|
||||
function pull_installer() {
|
||||
gcloud docker pull "${KUBE_ANYWHERE_FEDERATION_IMAGE}:${KUBE_ANYWHERE_FEDERATION_VERSION}"
|
||||
gcloud docker pull "${KUBE_ANYWHERE_FEDERATION_CHARTS_IMAGE}:${KUBE_ANYWHERE_FEDERATION_CHARTS_VERSION}"
|
||||
}
|
||||
|
||||
function kube_action() {
|
||||
docker run \
|
||||
--user="$(id -u):$(id -g)" \
|
||||
-m 12G \
|
||||
-v "${HOME}/.config/gcloud/application_default_credentials.json:/.config/gcloud/application_default_credentials.json:ro" \
|
||||
-v "${HOME}/.kube:/.kube" \
|
||||
-v "${FEDERATION_OUTPUT_ROOT}:/_output" \
|
||||
"${KUBE_ANYWHERE_FEDERATION_IMAGE}:${KUBE_ANYWHERE_FEDERATION_VERSION}" \
|
||||
"${ACTION}"
|
||||
}
|
||||
|
||||
function federation_action() {
|
||||
docker run \
|
||||
-m 12G \
|
||||
-v "${HOME}/.kube/config:/root/.kube/config:ro" \
|
||||
-v "${FEDERATION_OUTPUT_ROOT}:/_output" \
|
||||
"${KUBE_ANYWHERE_FEDERATION_CHARTS_IMAGE}:${KUBE_ANYWHERE_FEDERATION_CHARTS_VERSION}" \
|
||||
"${ACTION}"
|
||||
}
|
||||
|
||||
function gen_or_update_config() {
|
||||
if [[ "${KUBE_VERSION}" == *-dirty ]]; then
|
||||
KUBE_VERSION+=".$(dirty_sha)"
|
||||
fi
|
||||
|
||||
mkdir -p "${FEDERATION_OUTPUT_ROOT}"
|
||||
cp "config.default.json" "${FEDERATION_OUTPUT_ROOT}/config.json"
|
||||
|
||||
update_config \
|
||||
'[.[] | .phase1.gce.project |= "'"${KUBE_PROJECT}"'"]' \
|
||||
"${FEDERATION_OUTPUT_ROOT}/config.json"
|
||||
|
||||
# Not chaining for readability
|
||||
update_config \
|
||||
'[.[] | .phase2 = { docker_registry: "'"${KUBE_REGISTRY}"'", kubernetes_version: "'"${KUBE_VERSION}"'" } ]' \
|
||||
"${FEDERATION_OUTPUT_ROOT}/config.json"
|
||||
|
||||
cat <<EOF> "${FEDERATION_OUTPUT_ROOT}/values.yaml"
|
||||
apiserverRegistry: "${KUBE_REGISTRY}"
|
||||
apiserverVersion: "${KUBE_VERSION}"
|
||||
controllerManagerRegistry: "${KUBE_REGISTRY}"
|
||||
controllerManagerVersion: "${KUBE_VERSION}"
|
||||
EOF
|
||||
}
|
||||
|
||||
if [[ "${ACTION}" == "gen" || "${ACTION}" == "deploy" ]]; then
|
||||
gen_or_update_config
|
||||
|
||||
cd "${KUBE_ROOT}"
|
||||
build
|
||||
push
|
||||
pull_installer
|
||||
|
||||
kube_action
|
||||
federation_action
|
||||
else
|
||||
federation_action
|
||||
kube_action
|
||||
fi
|
|
@ -0,0 +1,83 @@
|
|||
[
|
||||
{
|
||||
"phase1": {
|
||||
"num_nodes": 3,
|
||||
"cluster_name": "cluster1-kubernetes",
|
||||
"cloud_provider": "gce",
|
||||
"cluster_cidr": "10.180.0.0/14",
|
||||
"gce": {
|
||||
"os_image": "ubuntu-1604-xenial-v20160420c",
|
||||
"instance_type": "n1-standard-2",
|
||||
"project": "",
|
||||
"region": "us-central1",
|
||||
"zone": "us-central1-a",
|
||||
"network": "federation"
|
||||
}
|
||||
},
|
||||
"phase2": {
|
||||
"docker_registry": "gcr.io/google-containers",
|
||||
"kubernetes_version": "v1.3.0"
|
||||
},
|
||||
"phase3": {
|
||||
"run_addons": true,
|
||||
"kube_proxy": true,
|
||||
"dashboard": true,
|
||||
"heapster": true,
|
||||
"kube_dns": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"phase1": {
|
||||
"num_nodes": 3,
|
||||
"cluster_name": "cluster2-kubernetes",
|
||||
"cloud_provider": "gce",
|
||||
"cluster_cidr": "10.184.0.0/14",
|
||||
"gce": {
|
||||
"os_image": "ubuntu-1604-xenial-v20160420c",
|
||||
"instance_type": "n1-standard-2",
|
||||
"project": "",
|
||||
"region": "us-central1",
|
||||
"zone": "us-central1-b",
|
||||
"network": "federation"
|
||||
}
|
||||
},
|
||||
"phase2": {
|
||||
"docker_registry": "gcr.io/google-containers",
|
||||
"kubernetes_version": "v1.3.0"
|
||||
},
|
||||
"phase3": {
|
||||
"run_addons": true,
|
||||
"kube_proxy": true,
|
||||
"dashboard": true,
|
||||
"heapster": true,
|
||||
"kube_dns": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"phase1": {
|
||||
"num_nodes": 3,
|
||||
"cluster_name": "cluster3-kubernetes",
|
||||
"cloud_provider": "gce",
|
||||
"cluster_cidr": "10.188.0.0/14",
|
||||
"gce": {
|
||||
"os_image": "ubuntu-1604-xenial-v20160420c",
|
||||
"instance_type": "n1-standard-2",
|
||||
"project": "",
|
||||
"region": "us-central1",
|
||||
"zone": "us-central1-f",
|
||||
"network": "federation"
|
||||
}
|
||||
},
|
||||
"phase2": {
|
||||
"docker_registry": "gcr.io/google-containers",
|
||||
"kubernetes_version": "v1.3.0"
|
||||
},
|
||||
"phase3": {
|
||||
"run_addons": true,
|
||||
"kube_proxy": true,
|
||||
"dashboard": true,
|
||||
"heapster": true,
|
||||
"kube_dns": true
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue