2019-06-17 10:38:54 +08:00
#!/bin/bash
#--------------------------------------------------
2021-01-07 09:30:50 +08:00
# This script is used for:
2019-06-17 10:38:54 +08:00
# 1. to download the scripts/binaries/images needed for installing a k8s cluster with kubeasz
2022-10-07 10:12:04 +08:00
# 2. to run kubeasz in a container (recommended)
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
#--------------------------------------------------
set -o nounset
set -o errexit
2022-10-20 20:14:00 +08:00
set -o pipefail
2019-06-17 10:38:54 +08:00
#set -o xtrace
2021-01-11 22:58:59 +08:00
# default settings, can be overridden by cmd line options, see usage
2023-12-27 22:18:07 +08:00
DOCKER_VER=24.0.7
2023-12-31 11:59:36 +08:00
KUBEASZ_VER=3.6.3
2023-12-27 22:18:07 +08:00
K8S_BIN_VER=v1.29.0
2023-09-03 12:31:13 +08:00
# https://github.com/easzlab/dockerfile-kubeasz-ext-bin
2023-12-27 22:18:07 +08:00
EXT_BIN_VER=1.9.0
2023-09-03 12:31:13 +08:00
# https://github.com/easzlab/dockerfile-kubeasz-sys-pkg
2023-05-06 19:37:43 +08:00
SYS_PKG_VER=1.0.0
2023-09-05 20:51:47 +08:00
HARBOR_VER=v2.8.4
2021-01-11 22:58:59 +08:00
REGISTRY_MIRROR=CN
2019-06-17 10:38:54 +08:00
2023-09-05 19:24:03 +08:00
# images downloaded by default(with 'ezdown -D')
2023-09-03 12:31:13 +08:00
# https://github.com/projectcalico/calico
2023-12-27 22:21:43 +08:00
calicoVer=v3.26.4
2023-09-03 12:31:13 +08:00
# https://github.com/coredns/coredns
corednsVer=1.11.1
# https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/
dnsNodeCacheVer=1.22.23
2022-12-20 09:23:15 +08:00
dashboardVer=v2.7.0
2022-05-30 20:52:45 +08:00
dashboardMetricsScraperVer=v1.0.8
2023-09-03 12:31:13 +08:00
# https://github.com/kubernetes-sigs/metrics-server
metricsVer=v0.6.4
2022-12-20 09:23:15 +08:00
pauseVer=3.9
2022-06-18 08:27:12 +08:00
2023-09-05 19:24:03 +08:00
# images not downloaded by default(only download with 'ezdown -X ***')
2023-09-03 12:31:13 +08:00
# https://github.com/cilium/cilium
2023-12-31 11:59:36 +08:00
ciliumVer=1.14.5
2023-09-03 12:31:13 +08:00
# https://github.com/flannel-io/flannel
flannelVer=v0.22.2
# https://github.com/cloudnativelabs/kube-router
2023-05-16 16:07:22 +08:00
kubeRouterVer=v1.5.4
2023-09-03 12:31:13 +08:00
# https://github.com/kubeovn/kube-ovn
2023-05-14 20:53:18 +08:00
kubeOvnVer=v1.11.5
2023-09-03 12:31:13 +08:00
# https://github.com/rancher/local-path-provisioner
2023-05-19 21:45:24 +08:00
localpathProvisionerVer=v0.0.24
2023-09-03 12:31:13 +08:00
# https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner
2022-01-05 12:43:03 +08:00
nfsProvisionerVer=v4.0.2
2023-11-25 08:47:22 +08:00
#https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
2023-05-02 16:40:50 +08:00
promChartVer=45.23.0
2023-11-25 08:47:22 +08:00
#https://github.com/bitnami/charts/tree/main/bitnami/kubeapps
2023-05-28 12:06:42 +08:00
kubeappsVer=12.4.3
2022-06-18 08:27:12 +08:00
2020-12-25 11:53:00 +08:00
function usage() {
echo -e "\033[33mUsage:\033[0m ezdown [options] [args]"
cat <<EOF
2022-06-18 08:27:12 +08:00
option:
2020-12-25 11:53:00 +08:00
-C stop&clean all local containers
2022-06-18 08:27:12 +08:00
-D download default binaries/images into "$BASE"
2023-05-06 19:37:43 +08:00
-P <OS> download system packages of the OS (ubuntu_22,debian_11,...)
2021-02-08 21:23:00 +08:00
-R download Registry(harbor) offline installer
2020-12-25 11:53:00 +08:00
-S start kubeasz in a container
2023-05-11 22:50:06 +08:00
-X <opt> download extra images
2020-12-25 11:53:00 +08:00
-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)
-z <ver> set kubeasz version, default "$KUBEASZ_VER"
EOF
}
2023-05-06 19:37:43 +08:00
function usage-down-sys-pkg(){
echo -e "\033[33mUsage:\033[0m ezdown -P <OS>"
cat <<EOF
available OSes:
2023-05-11 22:50:06 +08:00
almalinux_8 to download package of AlmaLinux 8
almalinux_9 to download package of AlmaLinux 9
centos_7 to download package of CentOS 7
debian_10 to download package of Debian 10
debian_11 to download package of Debian 11
fedora_34 to download package of Fedora 34
fedora_35 to download package of Fedora 35
fedora_36 to download package of Fedora 36
fedora_37 to download package of Fedora 37
opensuse_leap_15 to download package of openSUSE Leap 15
rocky_8 to download package of Rocky Linux 8
rocky_9 to download package of Rocky Linux 9
ubuntu_16 to download package of Ubuntu 16.04
ubuntu_18 to download package of Ubuntu 18.04
ubuntu_20 to download package of Ubuntu 20.04
ubuntu_22 to download package of Ubuntu 22.04
2023-05-06 19:37:43 +08:00
examples:
./ezdown -P ubuntu_22
EOF
}
2023-05-11 22:50:06 +08:00
function usage-down-ext-img(){
echo -e "\033[33mUsage:\033[0m ezdown -X <opt>"
cat <<EOF
available options:
2023-05-19 21:45:24 +08:00
cilium to download images of cilium
flannel to download images of flannel
kube-ovn to download images of kube-ovn
kube-router to download images of kube-router
2023-05-28 12:06:42 +08:00
kubeapps to download images of kubeapps
2023-05-19 21:45:24 +08:00
local-path-provisioner to download images of local-path-provisioner
network-check to download images of network-check
nfs-provisioner to download images of nfs-provisioner
prometheus to download images of prometheus
2023-05-11 22:50:06 +08:00
examples:
./ezdown -X prometheus
EOF
}
2020-12-25 11:53:00 +08:00
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
2022-10-01 22:59:21 +08:00
DOCKER_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/static/stable/${ARCH}/docker-${DOCKER_VER}.tgz"
2019-07-15 19:39:36 +08:00
else
2022-10-01 22:59:21 +08:00
DOCKER_URL="https://download.docker.com/linux/static/stable/${ARCH}/docker-${DOCKER_VER}.tgz"
2019-07-15 19:39:36 +08:00
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
2022-10-01 22:59:21 +08:00
logger info "downloading docker binaries, arch:$ARCH, version:$DOCKER_VER"
2021-10-15 12:50:34 +08:00
if [[ -e /usr/bin/wget ]];then
wget -c --no-check-certificate "$DOCKER_URL" || { logger error "downloading docker failed"; exit 1; }
2019-07-18 12:45:27 +08:00
else
2021-10-15 12:50:34 +08:00
curl -k -C- -O --retry 3 "$DOCKER_URL" || { logger error "downloading docker failed"; exit 1; }
2019-07-18 12:45:27 +08:00
fi
2022-10-01 22:59:21 +08:00
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
2021-01-07 09:30:50 +08:00
tar zxf "$BASE/down/docker-$DOCKER_VER.tgz" -C "$BASE/down" && \
2023-09-05 20:51:47 +08:00
mkdir -p "$BASE/bin/docker-bin" && \
cp -f "$BASE"/down/docker/* "$BASE/bin/docker-bin" && \
2022-10-01 22:59:21 +08:00
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
2023-02-09 22:28:03 +08:00
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
2019-06-17 10:38:54 +08:00
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
2021-04-24 21:37:15 +08:00
DOCKER_VER_MAIN=$(echo "$DOCKER_VER"|cut -d. -f1)
CGROUP_DRIVER="cgroupfs"
((DOCKER_VER_MAIN>=20)) && CGROUP_DRIVER="systemd"
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
{
2021-04-24 21:37:15 +08:00
"exec-opts": ["native.cgroupdriver=$CGROUP_DRIVER"],
2019-06-17 10:38:54 +08:00
"registry-mirrors": [
2022-11-23 19:47:32 +08:00
"https://docker.nju.edu.cn/",
"https://kuamavit.mirror.aliyuncs.com"
2019-06-17 10:38:54 +08:00
],
2022-06-09 22:33:46 +08:00
"insecure-registries": ["http://easzlab.io.local:5000"],
2019-06-17 10:38:54 +08:00
"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
{
2021-04-24 21:37:15 +08:00
"exec-opts": ["native.cgroupdriver=$CGROUP_DRIVER"],
2022-06-09 22:33:46 +08:00
"insecure-registries": ["http://easzlab.io.local:5000"],
2019-07-15 10:45:59 +08:00
"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
2023-08-23 20:59:48 +08:00
if [[ -f /etc/selinux/config ]]; then
2023-09-03 12:31:13 +08:00
logger debug "turn off selinux"
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
2023-09-05 19:24:03 +08:00
systemctl daemon-reload && systemctl restart docker && sleep 3
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
2023-05-11 22:50:06 +08:00
if [[ ! -f "$imageDir/kubeasz_$KUBEASZ_VER.tar" ]];then
logger info "downloading kubeasz: $KUBEASZ_VER"
docker pull "easzlab/kubeasz:$KUBEASZ_VER" && \
docker save -o "$imageDir/kubeasz_$KUBEASZ_VER.tar" "easzlab/kubeasz:$KUBEASZ_VER"
else
docker load -i "$imageDir/kubeasz_$KUBEASZ_VER.tar"
fi
2022-05-28 11:18:52 +08:00
docker ps -a |grep -q temp_easz && { logger debug "remove existing container"; docker rm -f temp_easz; }
2020-12-25 11:53:00 +08:00
logger debug " run a temporary container"
2023-05-11 22:50:06 +08:00
docker run -d --name temp_easz easzlab/kubeasz:${KUBEASZ_VER} || { logger error "failed."; exit 1; }
2019-07-10 18:29:07 +08:00
2023-02-19 09:34:59 +08:00
[[ -d "$BASE/down" ]] && /bin/mv -f "$BASE/down" /tmp
2021-01-07 09:30:50 +08:00
[[ -d "$BASE/bin" ]] && /bin/mv -f "$BASE/bin" /tmp
2019-07-10 18:29:07 +08:00
2021-01-07 09:30:50 +08:00
rm -rf "$BASE" && \
2020-12-25 11:53:00 +08:00
logger debug "cp kubeasz code from the temporary container" && \
2021-01-07 09:30:50 +08:00
docker cp "temp_easz:$BASE" "$BASE" && \
2020-12-25 11:53:00 +08:00
logger debug "stop&remove temporary container" && \
2019-07-10 18:29:07 +08:00
docker rm -f temp_easz
2021-01-07 09:30:50 +08:00
mkdir -p "$BASE/bin" "$BASE/down"
2023-02-19 09:34:59 +08:00
[[ -d "/tmp/down" ]] && /bin/mv -f /tmp/down/* "$BASE/down"
2021-01-07 09:30:50 +08:00
[[ -d "/tmp/bin" ]] && /bin/mv -f /tmp/bin/* "$BASE/bin"
2020-12-25 11:53:00 +08:00
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"
2022-09-13 16:34:21 +08:00
rm -rf "$BASE/k8s_bin_tmp"
2022-05-28 11:18:52 +08:00
docker ps -a |grep -q temp_k8s_bin && { logger debug "remove existing container"; docker rm -f temp_k8s_bin; }
2021-01-07 09:30:50 +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" && \
2021-01-07 09:30:50 +08:00
docker cp temp_k8s_bin:/k8s "$BASE/k8s_bin_tmp" && \
/bin/mv -f "$BASE"/k8s_bin_tmp/* "$BASE/bin" && \
2020-12-25 11:53:00 +08:00
logger debug "stop&remove temporary container" && \
2019-06-17 10:38:54 +08:00
docker rm -f temp_k8s_bin && \
2021-01-07 09:30:50 +08:00
rm -rf "$BASE/k8s_bin_tmp"
2019-06-17 10:38:54 +08:00
}
function get_ext_bin() {
2021-03-27 00:09:42 +08:00
[[ -f "$BASE/bin/etcdctl" ]] && { logger warn "extra 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"
2022-09-13 16:34:21 +08:00
rm -rf "$BASE/extra_bin_tmp"
2022-05-28 11:18:52 +08:00
docker ps -a |grep -q temp_ext_bin && { logger debug "remove existing container"; docker rm -f temp_ext_bin; }
2021-01-07 09:30:50 +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" && \
2021-01-07 09:30:50 +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" && \
2021-01-07 09:30:50 +08:00
docker cp temp_ext_bin:/extra "$BASE/extra_bin_tmp" && \
/bin/mv -f "$BASE"/extra_bin_tmp/* "$BASE/bin" && \
2020-12-25 11:53:00 +08:00
logger debug "stop&remove temporary container" && \
2019-06-17 10:38:54 +08:00
docker rm -f temp_ext_bin && \
2021-01-07 09:30:50 +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() {
2023-05-14 20:53:18 +08:00
[[ -f "$BASE/down/packages/$1.tgz" ]] && { logger warn "system packages for $1 existed"; return 0; }
2019-07-02 09:58:07 +08:00
2022-05-28 11:18:52 +08:00
docker ps -a |grep -q temp_sys_pkg && { logger debug "remove existing container"; docker rm -f temp_sys_pkg; }
2020-12-25 11:53:00 +08:00
logger info "downloading system packages kubeasz-sys-pkg:$SYS_PKG_VER"
2021-01-07 09:30:50 +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" && \
2021-01-07 09:30:50 +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" && \
2021-01-07 09:30:50 +08:00
docker cp temp_sys_pkg:/packages "$BASE/down" && \
2020-12-25 11:53:00 +08:00
logger debug "stop&remove temporary container" && \
2019-07-02 09:58:07 +08:00
docker rm -f temp_sys_pkg
}
2021-02-08 21:23:00 +08:00
function get_harbor_offline_pkg() {
[[ -f "$BASE/down/harbor-offline-installer-$HARBOR_VER.tgz" ]] && { logger warn "harbor-offline existed"; return 0; }
2022-05-28 11:18:52 +08:00
docker ps -a |grep -q temp_harbor && { logger debug "remove existing container"; docker rm -f temp_harbor; }
2021-02-08 21:23:00 +08:00
logger info "downloading harbor-offline:$HARBOR_VER"
docker pull "easzlab/harbor-offline:$HARBOR_VER" && \
logger debug "run a temporary container" && \
docker run -d --name temp_harbor "easzlab/harbor-offline:$HARBOR_VER" && \
logger debug "cp harbor-offline installer package" && \
docker cp "temp_harbor:/harbor-offline-installer-$HARBOR_VER.tgz" "$BASE/down" && \
logger debug "stop&remove temporary container" && \
docker rm -f temp_harbor
}
2022-06-18 08:27:12 +08:00
function get_default_images() {
logger info "download default images, then upload to the local registry"
2019-06-17 10:38:54 +08:00
2022-06-09 22:33:46 +08:00
# calico
2019-06-17 10:38:54 +08:00
if [[ ! -f "$imageDir/calico_$calicoVer.tar" ]];then
2021-01-07 09:30:50 +08:00
docker pull "calico/cni:$calicoVer" && \
docker pull "calico/kube-controllers:$calicoVer" && \
docker pull "calico/node:$calicoVer" && \
2022-09-08 21:10:33 +08:00
docker save -o "$imageDir/calico_$calicoVer.tar" "calico/cni:$calicoVer" "calico/kube-controllers:$calicoVer" "calico/node:$calicoVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/calico_$calicoVer.tar"
2019-06-17 10:38:54 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "calico/cni:$calicoVer" "easzlab.io.local:5000/calico/cni:$calicoVer"
docker push "easzlab.io.local:5000/calico/cni:$calicoVer"
docker tag "calico/kube-controllers:$calicoVer" "easzlab.io.local:5000/calico/kube-controllers:$calicoVer"
docker push "easzlab.io.local:5000/calico/kube-controllers:$calicoVer"
docker tag "calico/node:$calicoVer" "easzlab.io.local:5000/calico/node:$calicoVer"
docker push "easzlab.io.local:5000/calico/node:$calicoVer"
# coredns
2019-06-17 10:38:54 +08:00
if [[ ! -f "$imageDir/coredns_$corednsVer.tar" ]];then
2021-01-07 09:30:50 +08:00
docker pull "coredns/coredns:$corednsVer" && \
docker save -o "$imageDir/coredns_$corednsVer.tar" "coredns/coredns:$corednsVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/coredns_$corednsVer.tar"
2019-06-17 10:38:54 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "coredns/coredns:$corednsVer" "easzlab.io.local:5000/coredns/coredns:$corednsVer"
docker push "easzlab.io.local:5000/coredns/coredns:$corednsVer"
# dns-node-cache
2021-01-13 21:27:18 +08:00
if [[ ! -f "$imageDir/k8s-dns-node-cache_$dnsNodeCacheVer.tar" ]];then
docker pull "easzlab/k8s-dns-node-cache:$dnsNodeCacheVer" && \
docker save -o "$imageDir/k8s-dns-node-cache_$dnsNodeCacheVer.tar" "easzlab/k8s-dns-node-cache:$dnsNodeCacheVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/k8s-dns-node-cache_$dnsNodeCacheVer.tar"
2021-01-13 21:27:18 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "easzlab/k8s-dns-node-cache:$dnsNodeCacheVer" "easzlab.io.local:5000/easzlab/k8s-dns-node-cache:$dnsNodeCacheVer"
docker push "easzlab.io.local:5000/easzlab/k8s-dns-node-cache:$dnsNodeCacheVer"
# dashboard
2019-06-17 10:38:54 +08:00
if [[ ! -f "$imageDir/dashboard_$dashboardVer.tar" ]];then
2021-01-07 09:30:50 +08:00
docker pull "kubernetesui/dashboard:$dashboardVer" && \
docker save -o "$imageDir/dashboard_$dashboardVer.tar" "kubernetesui/dashboard:$dashboardVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/dashboard_$dashboardVer.tar"
2019-06-17 10:38:54 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "kubernetesui/dashboard:$dashboardVer" "easzlab.io.local:5000/kubernetesui/dashboard:$dashboardVer"
docker push "easzlab.io.local:5000/kubernetesui/dashboard:$dashboardVer"
# dashboard-metrics-scraper
2019-11-03 17:56:05 +08:00
if [[ ! -f "$imageDir/metrics-scraper_$dashboardMetricsScraperVer.tar" ]];then
2021-01-07 09:30:50 +08:00
docker pull "kubernetesui/metrics-scraper:$dashboardMetricsScraperVer" && \
docker save -o "$imageDir/metrics-scraper_$dashboardMetricsScraperVer.tar" "kubernetesui/metrics-scraper:$dashboardMetricsScraperVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/metrics-scraper_$dashboardMetricsScraperVer.tar"
2019-06-17 10:38:54 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "kubernetesui/metrics-scraper:$dashboardMetricsScraperVer" "easzlab.io.local:5000/kubernetesui/metrics-scraper:$dashboardMetricsScraperVer"
docker push "easzlab.io.local:5000/kubernetesui/metrics-scraper:$dashboardMetricsScraperVer"
# metrics-server
2019-06-17 10:38:54 +08:00
if [[ ! -f "$imageDir/metrics-server_$metricsVer.tar" ]];then
2021-09-24 18:08:36 +08:00
docker pull "easzlab/metrics-server:$metricsVer" && \
docker save -o "$imageDir/metrics-server_$metricsVer.tar" "easzlab/metrics-server:$metricsVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/metrics-server_$metricsVer.tar"
2019-06-17 10:38:54 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "easzlab/metrics-server:$metricsVer" "easzlab.io.local:5000/easzlab/metrics-server:$metricsVer"
docker push "easzlab.io.local:5000/easzlab/metrics-server:$metricsVer"
# pause
2019-06-17 10:38:54 +08:00
if [[ ! -f "$imageDir/pause_$pauseVer.tar" ]];then
2022-01-02 15:28:11 +08:00
docker pull "easzlab/pause:$pauseVer" && \
docker save -o "$imageDir/pause_$pauseVer.tar" "easzlab/pause:$pauseVer"
2022-06-09 22:33:46 +08:00
else
docker load -i "$imageDir/pause_$pauseVer.tar"
2019-06-17 10:38:54 +08:00
fi
2022-06-09 22:33:46 +08:00
docker tag "easzlab/pause:$pauseVer" "easzlab.io.local:5000/easzlab/pause:$pauseVer"
docker push "easzlab.io.local:5000/easzlab/pause:$pauseVer"
2022-06-18 08:27:12 +08:00
}
function get_extra_images() {
2023-05-11 22:50:06 +08:00
logger info "download images for $1, then upload to the local registry"
2022-06-18 08:27:12 +08:00
2023-05-11 22:50:06 +08:00
case "$1" in
# cilium images
cilium)
if [[ ! -f "$imageDir/cilium_$ciliumVer.tar" ]];then
docker pull "cilium/cilium:v$ciliumVer" && \
docker pull "cilium/operator-generic:v$ciliumVer" && \
docker pull "cilium/hubble-relay:v$ciliumVer" && \
2023-12-31 11:59:36 +08:00
docker pull cilium/hubble-ui-backend:v0.12.1 && \
docker pull cilium/hubble-ui:v0.12.1 && \
2023-05-11 22:50:06 +08:00
docker save -o "$imageDir/cilium_$ciliumVer.tar" "cilium/cilium:v$ciliumVer" \
"cilium/operator-generic:v$ciliumVer" \
"cilium/hubble-relay:v$ciliumVer" \
2023-12-31 11:59:36 +08:00
cilium/hubble-ui-backend:v0.12.1 \
cilium/hubble-ui:v0.12.1
2023-05-11 22:50:06 +08:00
else
docker load -i "$imageDir/cilium_$ciliumVer.tar"
fi
docker tag "cilium/cilium:v$ciliumVer" "easzlab.io.local:5000/cilium/cilium:v$ciliumVer"
docker push "easzlab.io.local:5000/cilium/cilium:v$ciliumVer"
docker tag "cilium/operator-generic:v$ciliumVer" "easzlab.io.local:5000/cilium/operator-generic:v$ciliumVer"
docker push "easzlab.io.local:5000/cilium/operator-generic:v$ciliumVer"
docker tag "cilium/hubble-relay:v$ciliumVer" "easzlab.io.local:5000/cilium/hubble-relay:v$ciliumVer"
docker push "easzlab.io.local:5000/cilium/hubble-relay:v$ciliumVer"
2023-12-31 11:59:36 +08:00
docker tag cilium/hubble-ui-backend:v0.12.1 easzlab.io.local:5000/cilium/hubble-ui-backend:v0.12.1
docker push easzlab.io.local:5000/cilium/hubble-ui-backend:v0.12.1
docker tag cilium/hubble-ui:v0.12.1 easzlab.io.local:5000/cilium/hubble-ui:v0.12.1
docker push easzlab.io.local:5000/cilium/hubble-ui:v0.12.1
2023-05-11 22:50:06 +08:00
;;
# flannel image
flannel)
if [[ ! -f "$imageDir/flannel_$flannelVer.tar" ]];then
docker pull "flannel/flannel:$flannelVer" && \
2023-09-03 12:31:13 +08:00
docker pull "flannel/flannel-cni-plugin:v1.2.0" && \
docker save -o "$imageDir/flannel_$flannelVer.tar" "flannel/flannel:$flannelVer" "flannel/flannel-cni-plugin:v1.2.0"
2023-05-11 22:50:06 +08:00
else
docker load -i "$imageDir/flannel_$flannelVer.tar"
fi
docker tag "flannel/flannel:$flannelVer" "easzlab.io.local:5000/flannel/flannel:$flannelVer"
docker push "easzlab.io.local:5000/flannel/flannel:$flannelVer"
2023-09-03 12:31:13 +08:00
docker tag "flannel/flannel-cni-plugin:v1.2.0" "easzlab.io.local:5000/flannel/flannel-cni-plugin:v1.2.0"
docker push "easzlab.io.local:5000/flannel/flannel-cni-plugin:v1.2.0"
2023-05-11 22:50:06 +08:00
;;
2023-05-28 12:06:42 +08:00
# kubeapps images
kubeapps)
if [[ ! -f "$imageDir/kubeapps_$kubeappsVer.tar" ]];then
docker pull "bitnami/kubeapps-apis:2.7.0-debian-11-r10" && \
docker pull "bitnami/kubeapps-apprepository-controller:2.7.0-scratch-r0" && \
docker pull "bitnami/kubeapps-asset-syncer:2.7.0-scratch-r0" && \
docker pull "bitnami/kubeapps-dashboard:2.7.0-debian-11-r12" && \
docker pull "bitnami/nginx:1.23.4-debian-11-r18" && \
docker pull "bitnami/postgresql:15.3.0-debian-11-r0" && \
docker save -o "$imageDir/kubeapps_$kubeappsVer.tar" \
"bitnami/kubeapps-apis:2.7.0-debian-11-r10" \
"bitnami/kubeapps-apprepository-controller:2.7.0-scratch-r0" \
"bitnami/kubeapps-asset-syncer:2.7.0-scratch-r0" \
"bitnami/kubeapps-dashboard:2.7.0-debian-11-r12" \
"bitnami/nginx:1.23.4-debian-11-r18" \
"bitnami/postgresql:15.3.0-debian-11-r0"
else
docker load -i "$imageDir/kubeapps_$kubeappsVer.tar"
fi
docker tag "bitnami/kubeapps-apis:2.7.0-debian-11-r10" "easzlab.io.local:5000/bitnami/kubeapps-apis:2.7.0-debian-11-r10"
docker tag "bitnami/kubeapps-apprepository-controller:2.7.0-scratch-r0" "easzlab.io.local:5000/bitnami/kubeapps-apprepository-controller:2.7.0-scratch-r0"
docker tag "bitnami/kubeapps-asset-syncer:2.7.0-scratch-r0" "easzlab.io.local:5000/bitnami/kubeapps-asset-syncer:2.7.0-scratch-r0"
docker tag "bitnami/kubeapps-dashboard:2.7.0-debian-11-r12" "easzlab.io.local:5000/bitnami/kubeapps-dashboard:2.7.0-debian-11-r12"
docker tag "bitnami/nginx:1.23.4-debian-11-r18" "easzlab.io.local:5000/bitnami/nginx:1.23.4-debian-11-r18"
docker tag "bitnami/postgresql:15.3.0-debian-11-r0" "easzlab.io.local:5000/bitnami/postgresql:15.3.0-debian-11-r0"
docker push "easzlab.io.local:5000/bitnami/kubeapps-apis:2.7.0-debian-11-r10"
docker push "easzlab.io.local:5000/bitnami/kubeapps-apprepository-controller:2.7.0-scratch-r0"
docker push "easzlab.io.local:5000/bitnami/kubeapps-asset-syncer:2.7.0-scratch-r0"
docker push "easzlab.io.local:5000/bitnami/kubeapps-dashboard:2.7.0-debian-11-r12"
docker push "easzlab.io.local:5000/bitnami/nginx:1.23.4-debian-11-r18"
docker push "easzlab.io.local:5000/bitnami/postgresql:15.3.0-debian-11-r0"
;;
2023-05-14 20:53:18 +08:00
# kube-ovn images
kube-ovn)
if [[ ! -f "$imageDir/kube-ovn_$kubeOvnVer.tar" ]];then
docker pull "kubeovn/kube-ovn:$kubeOvnVer" && \
docker save -o "$imageDir/kube-ovn_$kubeOvnVer.tar" "kubeovn/kube-ovn:$kubeOvnVer"
else
docker load -i "$imageDir/kube-ovn_$kubeOvnVer.tar"
fi
docker tag "kubeovn/kube-ovn:$kubeOvnVer" "easzlab.io.local:5000/kubeovn/kube-ovn:$kubeOvnVer"
docker push "easzlab.io.local:5000/kubeovn/kube-ovn:$kubeOvnVer"
;;
2023-05-16 16:07:22 +08:00
# kube-router images
kube-router)
if [[ ! -f "$imageDir/kube-router_$kubeRouterVer.tar" ]];then
docker pull "cloudnativelabs/kube-router:$kubeRouterVer" && \
docker save -o "$imageDir/kube-router_$kubeRouterVer.tar" "cloudnativelabs/kube-router:$kubeRouterVer"
else
docker load -i "$imageDir/kube-router_$kubeRouterVer.tar"
fi
docker tag "cloudnativelabs/kube-router:$kubeRouterVer" "easzlab.io.local:5000/cloudnativelabs/kube-router:$kubeRouterVer"
docker push "easzlab.io.local:5000/cloudnativelabs/kube-router:$kubeRouterVer"
;;
2023-05-19 21:45:24 +08:00
# local-path-provisioner image
local-path-provisioner)
if [[ ! -f "$imageDir/local-path-provisioner_$localpathProvisionerVer.tar" ]];then
docker pull "rancher/local-path-provisioner:$localpathProvisionerVer" && \
docker save -o "$imageDir/local-path-provisioner_$localpathProvisionerVer.tar" "rancher/local-path-provisioner:$localpathProvisionerVer"
else
docker load -i "$imageDir/local-path-provisioner_$localpathProvisionerVer.tar"
fi
docker tag "rancher/local-path-provisioner:$localpathProvisionerVer" "easzlab.io.local:5000/rancher/local-path-provisioner:$localpathProvisionerVer"
docker push "easzlab.io.local:5000/rancher/local-path-provisioner:$localpathProvisionerVer"
;;
2023-05-11 22:50:06 +08:00
# network-check images
network-check)
if [[ ! -f "$imageDir/network-check.tar" ]];then
docker pull easzlab/json-mock:v1.3.0 && \
docker pull easzlab/alpine-curl:v7.85.0 && \
docker save -o "$imageDir/network-check.tar" easzlab/json-mock:v1.3.0 easzlab/alpine-curl:v7.85.0
else
docker load -i "$imageDir/network-check.tar"
fi
docker tag easzlab/json-mock:v1.3.0 easzlab.io.local:5000/cilium/json-mock:v1.3.0
docker push easzlab.io.local:5000/cilium/json-mock:v1.3.0
docker tag easzlab/alpine-curl:v7.85.0 easzlab.io.local:5000/easzlab/alpine-curl:v7.85.0
docker push easzlab.io.local:5000/easzlab/alpine-curl:v7.85.0
;;
# nfs-provisioner image
nfs-provisioner)
if [[ ! -f "$imageDir/nfs-provisioner_$nfsProvisionerVer.tar" ]];then
docker pull "easzlab/nfs-subdir-external-provisioner:$nfsProvisionerVer" && \
docker save -o "$imageDir/nfs-provisioner_$nfsProvisionerVer.tar" "easzlab/nfs-subdir-external-provisioner:$nfsProvisionerVer"
else
docker load -i "$imageDir/nfs-provisioner_$nfsProvisionerVer.tar"
fi
docker tag "easzlab/nfs-subdir-external-provisioner:$nfsProvisionerVer" "easzlab.io.local:5000/easzlab/nfs-subdir-external-provisioner:$nfsProvisionerVer"
docker push "easzlab.io.local:5000/easzlab/nfs-subdir-external-provisioner:$nfsProvisionerVer"
;;
# prometheus chart images
prometheus)
if [[ ! -f "$imageDir/prometheus-chart_$promChartVer.tar" ]];then
docker pull easzlab/kube-state-metrics:v2.8.2 && \
docker pull easzlab/kube-webhook-certgen:v1.5.1 && \
docker pull grafana/grafana:9.4.7 && \
docker pull quay.io/kiwigrid/k8s-sidecar:1.22.0 && \
docker pull quay.io/prometheus-operator/prometheus-config-reloader:v0.63.0 && \
docker pull quay.io/prometheus-operator/prometheus-operator:v0.63.0 && \
docker pull quay.io/prometheus/alertmanager:v0.25.0 && \
docker pull quay.io/prometheus/node-exporter:v1.5.0 && \
docker pull quay.io/prometheus/prometheus:v2.42.0 && \
docker save -o "$imageDir/prometheus-chart_$promChartVer.tar" \
easzlab/kube-state-metrics:v2.8.2 \
easzlab/kube-webhook-certgen:v1.5.1 \
grafana/grafana:9.4.7 \
quay.io/kiwigrid/k8s-sidecar:1.22.0 \
quay.io/prometheus-operator/prometheus-config-reloader:v0.63.0 \
quay.io/prometheus-operator/prometheus-operator:v0.63.0 \
quay.io/prometheus/alertmanager:v0.25.0 \
quay.io/prometheus/node-exporter:v1.5.0 \
quay.io/prometheus/prometheus:v2.42.0
else
docker load -i "$imageDir/prometheus-chart_$promChartVer.tar"
fi
docker tag easzlab/kube-state-metrics:v2.8.2 easzlab.io.local:5000/prometheus/kube-state-metrics:v2.8.2
docker push easzlab.io.local:5000/prometheus/kube-state-metrics:v2.8.2
docker tag easzlab/kube-webhook-certgen:v1.5.1 easzlab.io.local:5000/prometheus/kube-webhook-certgen:v1.5.1
docker push easzlab.io.local:5000/prometheus/kube-webhook-certgen:v1.5.1
docker tag grafana/grafana:9.4.7 easzlab.io.local:5000/prometheus/grafana:9.4.7
docker push easzlab.io.local:5000/prometheus/grafana:9.4.7
docker tag quay.io/kiwigrid/k8s-sidecar:1.22.0 easzlab.io.local:5000/prometheus/k8s-sidecar:1.22.0
docker push easzlab.io.local:5000/prometheus/k8s-sidecar:1.22.0
docker tag quay.io/prometheus-operator/prometheus-config-reloader:v0.63.0 easzlab.io.local:5000/prometheus/prometheus-config-reloader:v0.63.0
docker push easzlab.io.local:5000/prometheus/prometheus-config-reloader:v0.63.0
docker tag quay.io/prometheus-operator/prometheus-operator:v0.63.0 easzlab.io.local:5000/prometheus/prometheus-operator:v0.63.0
docker push easzlab.io.local:5000/prometheus/prometheus-operator:v0.63.0
docker tag quay.io/prometheus/alertmanager:v0.25.0 easzlab.io.local:5000/prometheus/alertmanager:v0.25.0
docker push easzlab.io.local:5000/prometheus/alertmanager:v0.25.0
docker tag quay.io/prometheus/node-exporter:v1.5.0 easzlab.io.local:5000/prometheus/node-exporter:v1.5.0
docker push easzlab.io.local:5000/prometheus/node-exporter:v1.5.0
docker tag quay.io/prometheus/prometheus:v2.42.0 easzlab.io.local:5000/prometheus/prometheus:v2.42.0
docker push easzlab.io.local:5000/prometheus/prometheus:v2.42.0
;;
*)
logger error "invalid option: $1"
usage-down-ext-img
exit 1
;;
esac
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 && \
2022-06-09 22:33:46 +08:00
start_local_registry && \
2022-06-18 08:27:12 +08:00
get_default_images
2019-06-17 10:38:54 +08:00
}
2022-06-09 22:33:46 +08:00
function start_local_registry() {
2022-12-20 09:23:15 +08:00
docker ps -a --format="{{ .Names }}"|grep local_registry > /dev/null 2>&1 && \
{ logger warn "local_registry is already running"; return 0; }
2022-06-09 22:33:46 +08:00
if [[ ! -f "$imageDir/registry-2.tar" ]];then
docker pull "registry:2" && \
docker save -o "$imageDir/registry-2.tar" "registry:2"
fi
logger info "start local registry ..."
docker load -i "$imageDir/registry-2.tar" > /dev/null
mkdir -p /opt/kube/registry
docker run -d \
2022-12-20 09:23:15 +08:00
--name local_registry \
2022-06-09 22:33:46 +08:00
--network host \
--restart always \
--volume /opt/kube/registry:/var/lib/registry \
registry:2
sed -i "/easzlab.io.local/d" /etc/hosts
echo "127.0.0.1 easzlab.io.local" >> /etc/hosts
}
2019-06-17 10:38:54 +08:00
function start_kubeasz_docker() {
2023-01-11 15:54:41 +08:00
# create cmd alias in /root/.bashrc
sed -i '/docker exec/d' /root/.bashrc
echo "alias dk='docker exec -it kubeasz' # generated by kubeasz" >> /root/.bashrc
2020-12-25 11:53:00 +08:00
[[ -d "$BASE/roles/kube-node" ]] || { logger error "not initialized. try 'ezdown -D' first."; exit 1; }
2022-06-11 10:48:55 +08:00
docker ps -a --format="{{ .Names }}"|grep kubeasz > /dev/null 2>&1 && \
2023-04-24 10:59:49 +08:00
docker rm -f kubeasz > /dev/null
2019-06-17 10:38:54 +08:00
2023-05-22 15:19:29 +08:00
if [[ ! -f "$imageDir/kubeasz_$KUBEASZ_VER.tar" ]];then
logger info "downloading kubeasz: $KUBEASZ_VER"
docker pull "easzlab/kubeasz:$KUBEASZ_VER" && \
docker save -o "$imageDir/kubeasz_$KUBEASZ_VER.tar" "easzlab/kubeasz:$KUBEASZ_VER"
else
docker load -i "$imageDir/kubeasz_$KUBEASZ_VER.tar"
fi
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
2021-04-17 10:49:39 +08:00
host_if=$(ip route|grep default|head -n1|cut -d' ' -f5)
host_ip=$(ip a|grep "$host_if$"|head -n1|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
2019-06-17 10:38:54 +08:00
# run kubeasz docker container
docker run --detach \
2021-04-24 20:23:06 +08:00
--env HOST_IP="$host_ip" \
2019-06-17 10:38:54 +08:00
--name kubeasz \
2021-04-24 20:23:06 +08:00
--network host \
2019-06-17 10:38:54 +08:00
--restart always \
2021-01-07 09:30:50 +08:00
--volume "$BASE":"$BASE" \
2019-06-17 10:38:54 +08:00
--volume /root/.kube:/root/.kube \
2021-01-07 09:30:50 +08:00
--volume /root/.ssh:/root/.ssh \
2022-05-30 11:08:15 +08:00
--volume /etc/docker:/etc/docker \
2023-04-24 10:59:49 +08:00
easzlab/kubeasz:${KUBEASZ_VER}
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"
2022-06-09 22:33:46 +08:00
imageDir="$BASE/down"
2020-12-25 11:53:00 +08:00
2019-06-17 10:38:54 +08:00
# check if use bash shell
2022-03-25 10:23:26 +08:00
readlink /proc/$$/exe|grep -q "bash" || { 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; }
2022-10-01 22:59:21 +08:00
# get architecture
2022-10-23 08:49:09 +08:00
ARCH=$(uname -m)
2022-10-01 22:59:21 +08:00
2019-06-17 10:38:54 +08:00
[[ "$#" -eq 0 ]] && { usage >&2; exit 1; }
ACTION=""
2023-05-11 22:50:06 +08:00
while getopts "CDP:RSX:d:e:k:m: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)
2023-05-06 19:37:43 +08:00
[[ $OPTARG =~ (ubuntu_[0-9]+|centos_[0-9]+|debian_[0-9]+|fedora_[0-9]+|almalinux_[0-9]+|opensuse_leap_[0-9]+|rocky_[0-9]+) ]] || \
{ usage-down-sys-pkg; exit 1; }
SYS_PKG_VER="${SYS_PKG_VER}_$OPTARG"
2023-05-14 20:53:18 +08:00
ACTION="get_sys_pkg $OPTARG"
2020-05-24 14:51:01 +08:00
;;
2021-02-08 21:23:00 +08:00
R)
ACTION="get_harbor_offline_pkg"
;;
2019-06-17 10:38:54 +08:00
S)
ACTION="start_kubeasz_docker"
;;
2022-06-18 08:27:12 +08:00
X)
2023-05-11 22:50:06 +08:00
ACTION="get_extra_images $OPTARG"
2022-10-01 22:59:21 +08:00
;;
2019-06-17 10:38:54 +08:00
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-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 "$@"