From ad0ba3c5f3246b76da18f0e989036c4fba1b11f8 Mon Sep 17 00:00:00 2001 From: pixiake Date: Mon, 9 Nov 2020 00:49:07 +0800 Subject: [PATCH] update download script Signed-off-by: pixiake --- README.md | 7 ++- README_zh-CN.md | 3 + pkg/cluster/preinstall/preinstall.go | 8 +-- scripts/downloadKubekey.sh | 83 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 6 deletions(-) create mode 100755 scripts/downloadKubekey.sh diff --git a/README.md b/README.md index a15649f4b..8aac28033 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ KubeKey can install Kubernetes and KubeSphere together. The dependency that need ## Usage -### Get the Installer Excutable File +### Get the Installer Executable File * Binary downloads of the KubeKey can be found on the [Releases page](https://github.com/kubesphere/kubekey/releases). Unpack the binary and you are good to go! @@ -93,7 +93,7 @@ KubeKey can install Kubernetes and KubeSphere together. The dependency that need > Note: > > * Docker needs to be installed before building. -> * If you have problem to access `https://proxy.golang.org/`, excute `build.sh -p` instead. +> * If you have problem to access `https://proxy.golang.org`, execute `build.sh -p` instead. ### Create a Cluster @@ -105,6 +105,7 @@ Quick Start is for `all-in-one` installation which is a good start to get famili ##### Command +> If you have problem to access `https://storage.googleapis.com`, execute first `export KKZONE=cn`. ```shell script ./kk create cluster [--with-kubernetes version] [--with-kubesphere version] ``` @@ -133,6 +134,8 @@ Quick Start is for `all-in-one` installation which is a good start to get famili You have more control to customize parameters or create a multi-node cluster using the advanced installation. Specifically, create a cluster by specifying a configuration file. +> If you have problem to access `https://storage.googleapis.com`, execute first `export KKZONE=cn`. + 1. First, create an example configuration file ```shell script diff --git a/README_zh-CN.md b/README_zh-CN.md index 19e358b78..67d2ff20d 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -106,6 +106,7 @@ KubeKey 可以同时安装 Kubernetes 和 KubeSphere。根据 KubeSphere 所安 > 注意: 由于 Kubernetes 暂不支持大写 NodeName, hostname 中包含大写字母将导致后续安装过程无法正常结束 ##### 命令 +> 如果无法访问 `https://storage.googleapis.com`, 请先执行 `export KKZONE=cn`. ```shell script ./kk create cluster [--with-kubernetes version] [--with-kubesphere version] @@ -135,6 +136,8 @@ KubeKey 可以同时安装 Kubernetes 和 KubeSphere。根据 KubeSphere 所安 您可以使用高级安装来控制自定义参数或创建多节点群集。具体来说,通过指定配置文件来创建集群。 +> 如果无法访问 `https://storage.googleapis.com`, 请先执行 `export KKZONE=cn`. + 1. 首先,创建一个示例配置文件 ```shell script diff --git a/pkg/cluster/preinstall/preinstall.go b/pkg/cluster/preinstall/preinstall.go index f95146103..5bee0679a 100644 --- a/pkg/cluster/preinstall/preinstall.go +++ b/pkg/cluster/preinstall/preinstall.go @@ -59,9 +59,9 @@ func FilesDownloadHttp(mgr *manager.Manager, filepath, version, arch string) err helm.GetCmd = fmt.Sprintf("curl -o %s/helm-%s-linux-%s.tar.gz %s && cd %s && tar -zxf helm-%s-linux-%s.tar.gz && mv linux-%s/helm . && rm -rf *linux-%s*", filepath, helm.Version, helm.Arch, helm.Url, filepath, helm.Version, helm.Arch, helm.Arch, helm.Arch) } - kubeadm.GetCmd = fmt.Sprintf("curl -o %s %s", kubeadm.Path, kubeadm.Url) - kubelet.GetCmd = fmt.Sprintf("curl -o %s %s", kubelet.Path, kubelet.Url) - kubectl.GetCmd = fmt.Sprintf("curl -o %s %s", kubectl.Path, kubectl.Url) + kubeadm.GetCmd = fmt.Sprintf("curl -L -o %s %s", kubeadm.Path, kubeadm.Url) + kubelet.GetCmd = fmt.Sprintf("curl -L -o %s %s", kubelet.Path, kubelet.Url) + kubectl.GetCmd = fmt.Sprintf("curl -L -o %s %s", kubectl.Path, kubectl.Url) kubecni.GetCmd = fmt.Sprintf("curl -L -o %s %s", kubecni.Path, kubecni.Url) binaries := []files.KubeBinary{kubeadm, kubelet, kubectl, helm, kubecni} @@ -72,7 +72,7 @@ func FilesDownloadHttp(mgr *manager.Manager, filepath, version, arch string) err for i := 5; i > 0; i-- { if output, err := exec.Command("/bin/sh", "-c", binary.GetCmd).CombinedOutput(); err != nil { fmt.Println(string(output)) - return errors.Wrap(err, fmt.Sprintf("Failed to download %s binary", binary.Name)) + return errors.New(fmt.Sprintf("Failed to download %s binary: %s", binary.Name, binary.GetCmd)) } if err := SHA256Check(binary, version); err != nil { diff --git a/scripts/downloadKubekey.sh b/scripts/downloadKubekey.sh new file mode 100755 index 000000000..eac110bdd --- /dev/null +++ b/scripts/downloadKubekey.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# Copyright 2020 The KubeSphere 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. + +if [ "x$(uname)" = "xDarwin" ]; then + OSTYPE="osx" +else + OSTYPE="linux" +fi + +if [ "x${KUBEKEY_VERSION}" = "x" ]; then + KUBEKEY_VERSION="$(curl -sL https://api.github.com/repos/kubesphere/kubekey/releases | + grep -o 'download/v[0-9]*.[0-9]*.[0-9]*/' | + sort --version-sort | + tail -1 | awk -F'/' '{ print $2}')" + KUBEKEY_VERSION="${KUBEKEY_VERSION##*/}" +fi + +if [ -z "${ARCH}" ]; then + case "$(uname -m)" in + x86_64) + ARCH=amd64 + ;; + armv8*) + ARCH=arm64 + ;; + aarch64*) + ARCH=arm64 + ;; + armv*) + ARCH=armv7 + ;; + *) + echo "${ARCH}, isn't supported" + exit 1 + ;; + esac +fi + +if [ "x${KUBEKEY_VERSION}" = "x" ]; then + echo "Unable to get latest Kubekey version. Set KUBEKEY_VERSION env var and re-run. For example: export KUBEKEY_VERSION=v1.0.0" + echo "" + exit +fi + +DOWNLOAD_URL="https://github.com/kubesphere/kubekey/releases/download/${KUBEKEY_VERSION}/kubekey-${KUBEKEY_VERSION}-${OSTYPE}-${ARCH}.tar.gz" +if [ "x${KKZONE}" = "xcn" ]; then + DOWNLOAD_URL="https://kubernetes.pek3b.qingstor.com/kubekey/releases/download/${KUBEKEY_VERSION}/kubekey-${KUBEKEY_VERSION}-${OSTYPE}-${ARCH}.tar.gz" +fi + +echo "" +echo "Downloading kubekey ${KUBEKEY_VERSION} from ${DOWNLOAD_URL} ..." +echo "" + +curl -fsLO "$DOWNLOAD_URL" +if [ $? -ne 0 ]; then + echo "" + echo "Failed to download Kubekey ${KUBEKEY_VERSION} !" + echo "" + echo "Please verify the version you are trying to download." + echo "" + exit +fi + +filename="kubekey-${KUBEKEY_VERSION}-${OSTYPE}-${ARCH}.tar.gz" +tar -xzf "${filename}" +# rm "${filename}" + +echo "" +echo "Kubekey ${KUBEKEY_VERSION} Download Complete!" +echo ""