2019-06-17 10:38:54 +08:00
|
|
|
#!/bin/bash
|
|
|
|
#--------------------------------------------------
|
|
|
|
# This script is for:
|
|
|
|
# 1. to download the scripts/binaries/images needed for installing a k8s cluster with kubeasz
|
2020-12-25 11:53:00 +08:00
|
|
|
# 2. to run kubeasz in a container (optional)
|
2019-06-17 10:38:54 +08:00
|
|
|
# @author: gjmzj
|
2020-12-25 11:53:00 +08:00
|
|
|
# @usage: ./ezdown
|
2019-06-17 10:38:54 +08:00
|
|
|
# @repo: https://github.com/easzlab/kubeasz
|
|
|
|
# @ref: https://github.com/kubeasz/dockerfiles
|
|
|
|
#--------------------------------------------------
|
|
|
|
set -o nounset
|
|
|
|
set -o errexit
|
|
|
|
#set -o xtrace
|
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
# default version, can be overridden by cmd line options, see usage
|
2020-12-18 10:23:55 +08:00
|
|
|
DOCKER_VER=19.03.14
|
2020-12-19 23:00:51 +08:00
|
|
|
KUBEASZ_VER=2.2.3
|
|
|
|
K8S_BIN_VER=v1.20.1
|
2020-12-18 10:23:55 +08:00
|
|
|
EXT_BIN_VER=0.8.1
|
2020-11-19 18:54:42 +08:00
|
|
|
SYS_PKG_VER=0.3.3
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-11-06 20:17:38 +08:00
|
|
|
# images needed by k8s cluster
|
2020-12-18 19:00:09 +08:00
|
|
|
calicoVer=v3.15.3
|
2020-12-30 11:25:54 +08:00
|
|
|
ciliumVer=v1.4.1
|
|
|
|
flannelVer=v0.13.0-amd64
|
|
|
|
kubeRouterVer=v0.3.1
|
|
|
|
kubeOvnVer=v1.5.3
|
2020-11-19 18:54:42 +08:00
|
|
|
corednsVer=1.7.1
|
2020-12-18 19:00:09 +08:00
|
|
|
dashboardVer=v2.1.0
|
|
|
|
dashboardMetricsScraperVer=v1.0.6
|
2020-11-19 18:54:42 +08:00
|
|
|
metricsVer=v0.3.6
|
|
|
|
pauseVer=3.2
|
2020-11-06 20:17:38 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
function usage() {
|
|
|
|
echo -e "\033[33mUsage:\033[0m ezdown [options] [args]"
|
|
|
|
cat <<EOF
|
|
|
|
option: -{DdekSz}
|
|
|
|
-C stop&clean all local containers
|
|
|
|
-D download all into "$BASE"
|
|
|
|
-P download system packages for offline installing
|
|
|
|
-S start kubeasz in a container
|
|
|
|
-d <ver> set docker-ce version, default "$DOCKER_VER"
|
|
|
|
-e <ver> set kubeasz-ext-bin version, default "$EXT_BIN_VER"
|
|
|
|
-k <ver> set kubeasz-k8s-bin version, default "$K8S_BIN_VER"
|
|
|
|
-m <str> set docker registry mirrors, default "CN"(used in Mainland,China)
|
|
|
|
-p <ver> set kubeasz-sys-pkg version, default "$SYS_PKG_VER"
|
|
|
|
-z <ver> set kubeasz version, default "$KUBEASZ_VER"
|
|
|
|
|
|
|
|
see more at https://github.com/kubeasz/dockerfiles
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function logger() {
|
|
|
|
TIMESTAMP=$(date +'%Y-%m-%d %H:%M:%S')
|
|
|
|
case "$1" in
|
|
|
|
debug)
|
|
|
|
echo -e "$TIMESTAMP \033[36mDEBUG\033[0m $2"
|
|
|
|
;;
|
|
|
|
info)
|
|
|
|
echo -e "$TIMESTAMP \033[32mINFO\033[0m $2"
|
|
|
|
;;
|
|
|
|
warn)
|
|
|
|
echo -e "$TIMESTAMP \033[33mWARN\033[0m $2"
|
|
|
|
;;
|
|
|
|
error)
|
|
|
|
echo -e "$TIMESTAMP \033[31mERROR\033[0m $2"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-05-24 14:51:01 +08:00
|
|
|
function download_docker() {
|
2019-07-15 19:39:36 +08:00
|
|
|
if [[ "$REGISTRY_MIRROR" == CN ]];then
|
|
|
|
DOCKER_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/static/stable/x86_64/docker-${DOCKER_VER}.tgz"
|
|
|
|
else
|
|
|
|
DOCKER_URL="https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VER}.tgz"
|
|
|
|
fi
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
if [[ -f "$BASE/down/docker-${DOCKER_VER}.tgz" ]];then
|
|
|
|
logger warn "docker binaries already existed"
|
2019-06-17 10:38:54 +08:00
|
|
|
else
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "downloading docker binaries, version $DOCKER_VER"
|
2019-07-18 12:45:27 +08:00
|
|
|
if [[ -e /usr/bin/curl ]];then
|
2020-12-25 11:53:00 +08:00
|
|
|
curl -C- -O --retry 3 "$DOCKER_URL" || { logger error "downloading docker failed"; exit 1; }
|
2019-07-18 12:45:27 +08:00
|
|
|
else
|
2020-12-25 11:53:00 +08:00
|
|
|
wget -c "$DOCKER_URL" || { logger error "downloading docker failed"; exit 1; }
|
2019-07-18 12:45:27 +08:00
|
|
|
fi
|
2020-12-25 11:53:00 +08:00
|
|
|
/bin/mv -f ./docker-${DOCKER_VER}.tgz $BASE/down
|
2019-06-17 10:38:54 +08:00
|
|
|
fi
|
2020-11-19 18:54:42 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
tar zxf $BASE/down/docker-${DOCKER_VER}.tgz -C $BASE/down && \
|
|
|
|
/bin/cp -f $BASE/down/docker/* $BASE/bin && \
|
|
|
|
/bin/mv -f $BASE/down/docker/* /opt/kube/bin && \
|
2020-11-19 18:54:42 +08:00
|
|
|
ln -sf /opt/kube/bin/docker /bin/docker
|
2020-12-18 10:23:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_docker() {
|
|
|
|
# check if a container runtime is already installed
|
2020-12-25 11:53:00 +08:00
|
|
|
systemctl status docker|grep Active|grep -q running && { logger warn "docker is already running."; return 0; }
|
2020-05-24 14:51:01 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "generate docker service file"
|
2019-06-17 10:38:54 +08:00
|
|
|
cat > /etc/systemd/system/docker.service << EOF
|
|
|
|
[Unit]
|
|
|
|
Description=Docker Application Container Engine
|
|
|
|
Documentation=http://docs.docker.io
|
|
|
|
[Service]
|
|
|
|
Environment="PATH=/opt/kube/bin:/bin:/sbin:/usr/bin:/usr/sbin"
|
|
|
|
ExecStart=/opt/kube/bin/dockerd
|
|
|
|
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
|
|
|
|
ExecReload=/bin/kill -s HUP \$MAINPID
|
|
|
|
Restart=on-failure
|
|
|
|
RestartSec=5
|
|
|
|
LimitNOFILE=infinity
|
|
|
|
LimitNPROC=infinity
|
|
|
|
LimitCORE=infinity
|
|
|
|
Delegate=yes
|
|
|
|
KillMode=process
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
|
2019-07-15 10:45:59 +08:00
|
|
|
# configuration for dockerd
|
2020-05-24 14:51:01 +08:00
|
|
|
mkdir -p /etc/docker
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "generate docker config: /etc/docker/daemon.json"
|
2019-07-15 10:45:59 +08:00
|
|
|
if [[ "$REGISTRY_MIRROR" == CN ]];then
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "prepare register mirror for $REGISTRY_MIRROR"
|
2019-07-15 10:45:59 +08:00
|
|
|
cat > /etc/docker/daemon.json << EOF
|
2019-06-17 10:38:54 +08:00
|
|
|
{
|
|
|
|
"registry-mirrors": [
|
|
|
|
"https://docker.mirrors.ustc.edu.cn",
|
|
|
|
"http://hub-mirror.c.163.com"
|
|
|
|
],
|
|
|
|
"max-concurrent-downloads": 10,
|
|
|
|
"log-driver": "json-file",
|
|
|
|
"log-level": "warn",
|
|
|
|
"log-opts": {
|
|
|
|
"max-size": "10m",
|
|
|
|
"max-file": "3"
|
|
|
|
},
|
|
|
|
"data-root": "/var/lib/docker"
|
|
|
|
}
|
|
|
|
EOF
|
2019-07-15 10:45:59 +08:00
|
|
|
else
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "standard config without registry mirrors"
|
2019-07-15 10:45:59 +08:00
|
|
|
cat > /etc/docker/daemon.json << EOF
|
|
|
|
{
|
|
|
|
"max-concurrent-downloads": 10,
|
|
|
|
"log-driver": "json-file",
|
|
|
|
"log-level": "warn",
|
|
|
|
"log-opts": {
|
|
|
|
"max-size": "10m",
|
|
|
|
"max-file": "3"
|
|
|
|
},
|
|
|
|
"data-root": "/var/lib/docker"
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
fi
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2019-06-23 07:54:30 +08:00
|
|
|
if [[ -e /etc/centos-release || -e /etc/redhat-release ]]; then
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "turn off selinux in CentOS/Redhat"
|
2020-01-09 22:11:30 +08:00
|
|
|
getenforce|grep Disabled || setenforce 0
|
|
|
|
sed -i 's/^SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/config
|
2019-06-23 07:54:30 +08:00
|
|
|
fi
|
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "enable and start docker"
|
2019-06-17 10:38:54 +08:00
|
|
|
systemctl enable docker
|
2020-01-09 22:11:30 +08:00
|
|
|
systemctl daemon-reload && systemctl restart docker && sleep 4
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_kubeasz() {
|
|
|
|
# check if kubeasz already existed
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ -d "$BASE/roles/kube-node" ]] && { logger warn "kubeasz already existed"; return 0; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "downloading kubeasz: $KUBEASZ_VER"
|
|
|
|
logger debug " run a temporary container"
|
|
|
|
docker run -d --name temp_easz easzlab/kubeasz:${KUBEASZ_VER} || { logger error "download failed."; exit 1; }
|
2019-07-10 18:29:07 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ -f "$BASE/down/docker-${DOCKER_VER}.tgz" ]] && /bin/mv -f "$BASE/down/docker-${DOCKER_VER}.tgz" /tmp
|
|
|
|
[[ -d "$BASE/bin" ]] && /bin/mv -f $BASE/bin /tmp
|
2019-07-10 18:29:07 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
rm -rf $BASE && \
|
|
|
|
logger debug "cp kubeasz code from the temporary container" && \
|
|
|
|
docker cp temp_easz:$BASE $BASE && \
|
|
|
|
logger debug "stop&remove temporary container" && \
|
2019-07-10 18:29:07 +08:00
|
|
|
docker rm -f temp_easz
|
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
mkdir -p $BASE/bin
|
|
|
|
[[ -f "/tmp/docker-${DOCKER_VER}.tgz" ]] && /bin/mv -f "/tmp/docker-${DOCKER_VER}.tgz" $BASE/down
|
|
|
|
[[ -d "/tmp/bin" ]] && /bin/mv -f /tmp/bin/* $BASE/bin
|
|
|
|
return 0
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_k8s_bin() {
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ -f "$BASE/bin/kubelet" ]] && { logger warn "kubernetes binaries existed"; return 0; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "downloading kubernetes: $K8S_BIN_VER binaries"
|
2019-06-17 10:38:54 +08:00
|
|
|
docker pull easzlab/kubeasz-k8s-bin:${K8S_BIN_VER} && \
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "run a temporary container" && \
|
2019-06-17 10:38:54 +08:00
|
|
|
docker run -d --name temp_k8s_bin easzlab/kubeasz-k8s-bin:${K8S_BIN_VER} && \
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "cp k8s binaries" && \
|
|
|
|
docker cp temp_k8s_bin:/k8s $BASE/k8s_bin_tmp && \
|
|
|
|
/bin/mv -f $BASE/k8s_bin_tmp/* $BASE/bin && \
|
|
|
|
logger debug "stop&remove temporary container" && \
|
2019-06-17 10:38:54 +08:00
|
|
|
docker rm -f temp_k8s_bin && \
|
2020-12-25 11:53:00 +08:00
|
|
|
rm -rf $BASE/k8s_bin_tmp
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_ext_bin() {
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ -f "$BASE/bin/etcdctl" ]] && { logger warn "extral binaries existed"; return 0; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "downloading extral binaries kubeasz-ext-bin:$EXT_BIN_VER"
|
2019-06-17 10:38:54 +08:00
|
|
|
docker pull easzlab/kubeasz-ext-bin:${EXT_BIN_VER} && \
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "run a temporary container" && \
|
2019-06-17 10:38:54 +08:00
|
|
|
docker run -d --name temp_ext_bin easzlab/kubeasz-ext-bin:${EXT_BIN_VER} && \
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "cp extral binaries" && \
|
|
|
|
docker cp temp_ext_bin:/extra $BASE/extra_bin_tmp && \
|
|
|
|
/bin/mv -f $BASE/extra_bin_tmp/* $BASE/bin && \
|
|
|
|
logger debug "stop&remove temporary container" && \
|
2019-06-17 10:38:54 +08:00
|
|
|
docker rm -f temp_ext_bin && \
|
2020-12-25 11:53:00 +08:00
|
|
|
rm -rf $BASE/extra_bin_tmp
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:58:07 +08:00
|
|
|
function get_sys_pkg() {
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ -f "$BASE/down/packages/chrony_xenial.tar.gz" ]] && { logger warn "system packages existed"; return 0; }
|
2019-07-02 09:58:07 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "downloading system packages kubeasz-sys-pkg:$SYS_PKG_VER"
|
2019-07-02 09:58:07 +08:00
|
|
|
docker pull easzlab/kubeasz-sys-pkg:${SYS_PKG_VER} && \
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "run a temporary container" && \
|
2019-07-02 09:58:07 +08:00
|
|
|
docker run -d --name temp_sys_pkg easzlab/kubeasz-sys-pkg:${SYS_PKG_VER} && \
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "cp system packages" && \
|
|
|
|
docker cp temp_sys_pkg:/packages $BASE/down && \
|
|
|
|
logger debug "stop&remove temporary container" && \
|
2019-07-02 09:58:07 +08:00
|
|
|
docker rm -f temp_sys_pkg
|
|
|
|
}
|
|
|
|
|
2019-06-17 10:38:54 +08:00
|
|
|
function get_offline_image() {
|
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
imageDir=$BASE/down
|
|
|
|
[[ -d "$imageDir" ]] || { logger error "$imageDir not existed!"; exit 1; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "downloading offline images"
|
2019-06-17 10:38:54 +08:00
|
|
|
|
|
|
|
if [[ ! -f "$imageDir/calico_$calicoVer.tar" ]];then
|
2020-12-18 19:00:09 +08:00
|
|
|
docker pull "calico/cni:${calicoVer}" && \
|
2020-05-24 17:52:18 +08:00
|
|
|
docker pull "calico/pod2daemon-flexvol:${calicoVer}" && \
|
|
|
|
docker pull "calico/kube-controllers:${calicoVer}" && \
|
2020-12-18 19:00:09 +08:00
|
|
|
docker pull "calico/node:${calicoVer}" && \
|
2020-12-30 11:25:54 +08:00
|
|
|
docker save -o ${imageDir}/calico_${calicoVer}.tar calico/cni:${calicoVer} calico/kube-controllers:${calicoVer} calico/node:${calicoVer} calico/pod2daemon-flexvol:${calicoVer}
|
2019-06-17 10:38:54 +08:00
|
|
|
fi
|
|
|
|
if [[ ! -f "$imageDir/coredns_$corednsVer.tar" ]];then
|
|
|
|
docker pull coredns/coredns:${corednsVer} && \
|
|
|
|
docker save -o ${imageDir}/coredns_${corednsVer}.tar coredns/coredns:${corednsVer}
|
|
|
|
fi
|
|
|
|
if [[ ! -f "$imageDir/dashboard_$dashboardVer.tar" ]];then
|
2019-11-07 19:24:53 +08:00
|
|
|
docker pull kubernetesui/dashboard:${dashboardVer} && \
|
|
|
|
docker save -o ${imageDir}/dashboard_${dashboardVer}.tar kubernetesui/dashboard:${dashboardVer}
|
2019-06-17 10:38:54 +08:00
|
|
|
fi
|
|
|
|
if [[ ! -f "$imageDir/flannel_$flannelVer.tar" ]];then
|
|
|
|
docker pull easzlab/flannel:${flannelVer} && \
|
|
|
|
docker save -o ${imageDir}/flannel_${flannelVer}.tar easzlab/flannel:${flannelVer}
|
|
|
|
fi
|
2019-11-03 17:56:05 +08:00
|
|
|
if [[ ! -f "$imageDir/metrics-scraper_$dashboardMetricsScraperVer.tar" ]];then
|
|
|
|
docker pull kubernetesui/metrics-scraper:${dashboardMetricsScraperVer} && \
|
|
|
|
docker save -o ${imageDir}/metrics-scraper_${dashboardMetricsScraperVer}.tar kubernetesui/metrics-scraper:${dashboardMetricsScraperVer}
|
2019-06-17 10:38:54 +08:00
|
|
|
fi
|
|
|
|
if [[ ! -f "$imageDir/metrics-server_$metricsVer.tar" ]];then
|
|
|
|
docker pull mirrorgooglecontainers/metrics-server-amd64:${metricsVer} && \
|
|
|
|
docker save -o ${imageDir}/metrics-server_${metricsVer}.tar mirrorgooglecontainers/metrics-server-amd64:${metricsVer}
|
|
|
|
fi
|
|
|
|
if [[ ! -f "$imageDir/pause_$pauseVer.tar" ]];then
|
2020-05-03 19:59:31 +08:00
|
|
|
docker pull easzlab/pause-amd64:${pauseVer} && \
|
|
|
|
docker save -o ${imageDir}/pause_${pauseVer}.tar easzlab/pause-amd64:${pauseVer}
|
2020-04-10 19:10:30 +08:00
|
|
|
/bin/cp -u "${imageDir}/pause_${pauseVer}.tar" "${imageDir}/pause.tar"
|
2019-06-17 10:38:54 +08:00
|
|
|
fi
|
2019-06-29 18:46:50 +08:00
|
|
|
if [[ ! -f "$imageDir/kubeasz_$KUBEASZ_VER.tar" ]];then
|
|
|
|
docker pull easzlab/kubeasz:${KUBEASZ_VER} && \
|
|
|
|
docker save -o ${imageDir}/kubeasz_${KUBEASZ_VER}.tar easzlab/kubeasz:${KUBEASZ_VER}
|
|
|
|
fi
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function download_all() {
|
2020-12-25 11:53:00 +08:00
|
|
|
mkdir -p /opt/kube/bin "$BASE/down" "$BASE/bin"
|
2020-05-24 14:51:01 +08:00
|
|
|
download_docker && \
|
2019-06-17 10:38:54 +08:00
|
|
|
install_docker && \
|
|
|
|
get_kubeasz && \
|
|
|
|
get_k8s_bin && \
|
|
|
|
get_ext_bin && \
|
|
|
|
get_offline_image
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_kubeasz_docker() {
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ -d "$BASE/roles/kube-node" ]] || { logger error "not initialized. try 'ezdown -D' first."; exit 1; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "try to run kubeasz in a container"
|
2019-06-17 10:38:54 +08:00
|
|
|
# get host's IP
|
|
|
|
host_if=$(ip route|grep default|cut -d' ' -f5)
|
2019-06-24 22:19:47 +08:00
|
|
|
host_ip=$(ip a|grep "$host_if$"|awk '{print $2}'|cut -d'/' -f1)
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "get host IP: $host_ip"
|
2019-06-29 18:46:50 +08:00
|
|
|
|
2019-06-30 19:39:06 +08:00
|
|
|
# allow ssh login using key locally
|
|
|
|
if [[ ! -e /root/.ssh/id_rsa ]]; then
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "generate ssh key pair"
|
2019-06-30 19:39:06 +08:00
|
|
|
ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa > /dev/null
|
|
|
|
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
|
|
|
|
ssh-keyscan -t ecdsa -H "$host_ip" >> /root/.ssh/known_hosts
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create a link '/usr/bin/python' in Ubuntu1604
|
|
|
|
if [[ ! -e /usr/bin/python && -e /etc/debian_version ]]; then
|
2020-12-25 11:53:00 +08:00
|
|
|
logger debug "create a soft link '/usr/bin/python'"
|
2019-06-30 19:39:06 +08:00
|
|
|
ln -s /usr/bin/python3 /usr/bin/python
|
|
|
|
fi
|
|
|
|
|
2019-06-29 18:46:50 +08:00
|
|
|
#
|
2020-12-25 11:53:00 +08:00
|
|
|
docker load -i $BASE/down/kubeasz_${KUBEASZ_VER}.tar
|
2019-06-30 19:39:06 +08:00
|
|
|
|
2019-06-17 10:38:54 +08:00
|
|
|
# run kubeasz docker container
|
|
|
|
docker run --detach \
|
|
|
|
--name kubeasz \
|
|
|
|
--restart always \
|
|
|
|
--env HOST_IP="$host_ip" \
|
2020-12-25 11:53:00 +08:00
|
|
|
--volume $BASE:$BASE \
|
2019-06-17 10:38:54 +08:00
|
|
|
--volume /root/.kube:/root/.kube \
|
|
|
|
--volume /root/.ssh/id_rsa:/root/.ssh/id_rsa:ro \
|
|
|
|
--volume /root/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub:ro \
|
|
|
|
--volume /root/.ssh/known_hosts:/root/.ssh/known_hosts:ro \
|
2019-07-19 11:00:23 +08:00
|
|
|
easzlab/kubeasz:${KUBEASZ_VER} sleep 36000
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function clean_container() {
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "clean all running containers"
|
2019-06-17 10:38:54 +08:00
|
|
|
docker ps -a|awk 'NR>1{print $1}'|xargs docker rm -f
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
### Main Lines ##################################################
|
|
|
|
function main() {
|
2020-12-25 11:53:00 +08:00
|
|
|
BASE="/etc/kubeasz"
|
|
|
|
|
2019-06-17 10:38:54 +08:00
|
|
|
# check if use bash shell
|
2020-12-25 11:53:00 +08:00
|
|
|
readlink /proc/$$/exe|grep -q "dash" && { logger error "you should use bash shell, not sh"; exit 1; }
|
2019-06-17 10:38:54 +08:00
|
|
|
# check if use with root
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ "$EUID" -ne 0 ]] && { logger error "you should run this script as root"; exit 1; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
|
|
|
[[ "$#" -eq 0 ]] && { usage >&2; exit 1; }
|
|
|
|
|
2020-11-19 18:54:42 +08:00
|
|
|
REGISTRY_MIRROR="CN"
|
2019-06-17 10:38:54 +08:00
|
|
|
ACTION=""
|
2020-11-20 00:29:01 +08:00
|
|
|
while getopts "CDPSd:e:k:m:p:z:" OPTION; do
|
2019-06-17 10:38:54 +08:00
|
|
|
case "$OPTION" in
|
|
|
|
C)
|
|
|
|
ACTION="clean_container"
|
|
|
|
;;
|
|
|
|
D)
|
|
|
|
ACTION="download_all"
|
|
|
|
;;
|
2020-05-24 14:51:01 +08:00
|
|
|
P)
|
|
|
|
ACTION="get_sys_pkg"
|
|
|
|
;;
|
2019-06-17 10:38:54 +08:00
|
|
|
S)
|
|
|
|
ACTION="start_kubeasz_docker"
|
|
|
|
;;
|
|
|
|
d)
|
2020-11-19 18:54:42 +08:00
|
|
|
DOCKER_VER="$OPTARG"
|
2019-06-17 10:38:54 +08:00
|
|
|
;;
|
|
|
|
e)
|
2020-11-19 18:54:42 +08:00
|
|
|
EXT_BIN_VER="$OPTARG"
|
2019-06-17 10:38:54 +08:00
|
|
|
;;
|
|
|
|
k)
|
2020-11-19 18:54:42 +08:00
|
|
|
K8S_BIN_VER="$OPTARG"
|
2019-06-17 10:38:54 +08:00
|
|
|
;;
|
2019-07-15 10:45:59 +08:00
|
|
|
m)
|
2020-11-19 18:54:42 +08:00
|
|
|
REGISTRY_MIRROR="$OPTARG"
|
2019-07-15 10:45:59 +08:00
|
|
|
;;
|
2019-07-02 09:58:07 +08:00
|
|
|
p)
|
2020-11-19 18:54:42 +08:00
|
|
|
SYS_PKG_VER="$OPTARG"
|
2019-07-02 09:58:07 +08:00
|
|
|
;;
|
2019-06-17 10:38:54 +08:00
|
|
|
z)
|
2020-11-19 18:54:42 +08:00
|
|
|
KUBEASZ_VER="$OPTARG"
|
2020-09-28 11:46:42 +08:00
|
|
|
;;
|
2019-06-17 10:38:54 +08:00
|
|
|
?)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-12-25 11:53:00 +08:00
|
|
|
[[ "$ACTION" == "" ]] && { logger error "illegal option"; usage; exit 1; }
|
2019-06-17 10:38:54 +08:00
|
|
|
|
|
|
|
# excute cmd "$ACTION"
|
2020-12-25 11:53:00 +08:00
|
|
|
logger info "Action begin: $ACTION"
|
|
|
|
${ACTION} || { logger error "Action failed: $ACTION"; return 1; }
|
|
|
|
logger info "Action successed: $ACTION"
|
2019-06-17 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|