From 513162a5684abc63990884f41c7724b37649b829 Mon Sep 17 00:00:00 2001 From: Jiahui <4543bxy@gmail.com> Date: Mon, 16 Oct 2023 10:32:44 +0800 Subject: [PATCH] Fix/cloud init scripts (#4084) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix incorrect colon display; optimize:if avx is not supported, select the lower version of mongo; check cluster ready, can skip; fix costcenter app logo; add metrics server; * optimize * add db metrics * add cilium prompts * add openebs-backup sc --- deploy/cloud/README.md | 13 ++ deploy/cloud/manifests/db-metrics.yaml | 83 ++++++++ deploy/cloud/scripts/init.sh | 3 + .../deploy/manifests/appcr.yaml.tmpl | 2 +- scripts/cloud/install.sh | 182 +++++++++++++----- 5 files changed, 231 insertions(+), 52 deletions(-) create mode 100644 deploy/cloud/manifests/db-metrics.yaml diff --git a/deploy/cloud/README.md b/deploy/cloud/README.md index 29e40d6232e..1f4a02cae90 100644 --- a/deploy/cloud/README.md +++ b/deploy/cloud/README.md @@ -53,6 +53,19 @@ sealos apply -f Clusterfile Note: if you want to change pod cidr, please edit the `Clusterfile` before run `sealos apply` +### OpenEBS sc create + +```shell +kubectl create -f - < /dev/null + if [ $? -ne 0 ]; then + get_prompt "mongo_avx_requirement" + mongodb_version="mongodb-4.0" + fi +} # Initialization init() { @@ -120,16 +152,16 @@ collect_input() { # Master and Node IPs while :; do - read -p "$(get_prompt "input_master_ips")" masterIps - if validate_ips "$masterIps" && [[ ! -z "$masterIps" ]]; then + read -p "$(get_prompt "input_master_ips")" master_ips + if validate_ips "$master_ips" && [[ ! -z "$master_ips" ]]; then break else get_prompt "invalid_ips" fi done while :; do - read -p "$(get_prompt "input_node_ips")" nodeIps - if validate_ips "$nodeIps"; then + read -p "$(get_prompt "input_node_ips")" node_ips + if validate_ips "$node_ips"; then break else get_prompt "invalid_ips" @@ -140,22 +172,22 @@ collect_input() { ssh_private_key="${HOME}/.ssh/id_rsa" fi read -p "$(get_prompt "ssh_password")" ssh_password - read -p "$(get_prompt "pod_subnet")" podCidr - read -p "$(get_prompt "service_subnet")" serviceCidr - read -p "$(get_prompt "cloud_domain")" cloudDomain - read -p "$(get_prompt "cloud_port")" cloudPort - read -p "$(get_prompt "input_certificate")" inputCert - if [[ $inputCert == "y" || $inputCert == "Y" ]]; then - read -p "$(get_prompt "certificate_path")" certPath - read -p "$(get_prompt "private_key_path")" keyPath + read -p "$(get_prompt "pod_subnet")" pod_cidr + read -p "$(get_prompt "service_subnet")" service_cidr + read -p "$(get_prompt "cloud_domain")" cloud_domain + read -p "$(get_prompt "cloud_port")" cloud_port + read -p "$(get_prompt "input_certificate")" input_cert + if [[ $input_cert == "y" || $input_cert == "Y" ]]; then + read -p "$(get_prompt "certificate_path")" cert_path + read -p "$(get_prompt "private_key_path")" key_path fi } prepare_configs() { - if [[ $inputCert == "y" || $inputCert == "Y" ]]; then + if [[ -n "${cert_path}" ]] || [[ -n "${key_path}" ]]; then # Convert certificate and key to base64 - tls_crt_base64=$(cat $certPath | base64 | tr -d '\n') - tls_key_base64=$(cat $keyPath | base64 | tr -d '\n') + tls_crt_base64=$(cat $cert_path | base64 | tr -d '\n') + tls_key_base64=$(cat $key_path | base64 | tr -d '\n') # Define YAML content for certificate tls_config=" @@ -189,62 +221,110 @@ spec: kind: DaemonSet service: type: NodePort - match: docker.io/labring/ingress-nginx:v1.5.1 + match: docker.io/labring/ingress-nginx:v${ingress_nginx_version#v:-1.5.1} path: charts/ingress-nginx/values.yaml strategy: merge " echo "$ingress_config" > $CLOUD_DIR/ingress-nginx-config.yaml - sealos_gen_cmd="sealos gen labring/kubernetes:v1.25.6\ - labring/helm:v3.12.0\ - labring/cilium:v1.12.14\ - labring/cert-manager:v1.8.0\ - labring/openebs:v3.4.0\ - --masters $masterIps\ - --pk=${ssh_private_key}\ - --passwd=${ssh_password}\ - " - - if [ -n "$nodeIps" ]; then - sealos_gen_cmd+=" --nodes $nodeIps" + echo "master_ips= ${master_ips}" + sealos_gen_cmd="sealos gen labring/kubernetes:v${kubernetes_version#v:-1.25.6}\ + --masters $master_ips\ + --pk=${ssh_private_key:-$HOME/.ssh/id_rsa}\ + --passwd=${ssh_password} -o $CLOUD_DIR/Clusterfile" + + if [ -n "$node_ips" ]; then + sealos_gen_cmd+=" --nodes $node_ips" fi - $sealos_gen_cmd > $CLOUD_DIR/Clusterfile + command -v kubelet || $sealos_gen_cmd # Modify Clusterfile with sed - sed -i "s|100.64.0.0/10|${podCidr:-100.64.0.0/10}|g" $CLOUD_DIR/Clusterfile - sed -i "s|10.96.0.0/22|${serviceCidr:-10.96.0.0/22}|g" $CLOUD_DIR/Clusterfile + sed -i "s|100.64.0.0/10|${pod_cidr:-100.64.0.0/10}|g" $CLOUD_DIR/Clusterfile + sed -i "s|10.96.0.0/22|${service_cidr:-10.96.0.0/22}|g" $CLOUD_DIR/Clusterfile +} + +wait_cluster_ready() { + local prompt_msg=$(get_prompt "wait_cluster_ready") + while true; do + if kubectl get nodes | grep "NotReady" &> /dev/null; then + loading_animation "$prompt_msg" + else + echo && break # new line + fi + read -t 1 -n 1 -p "" input 2>/dev/null || true + if [[ "$input" == "1" ]]; then + echo && break # new line + fi + done +} + +loading_animation() { + local message="$1" + local duration="${2:-0.5}" + + echo -ne "\r$message \e[K" + sleep "$duration" + echo -ne "\r$message . \e[K" + sleep "$duration" + echo -ne "\r$message .. \e[K" + sleep "$duration" + echo -ne "\r$message ...\e[K" + sleep "$duration" } execute_commands() { get_prompt "k8s_installation" - sealos apply -f $CLOUD_DIR/Clusterfile + command -v kubelet || sealos apply -f $CLOUD_DIR/Clusterfile + command -v helm || sealos run "labring/helm:v${helm_version#v:-3.12.0}" + get_prompt "cilium_requirement" + if kubectl get no | grep NotReady &>/dev/null; then + sealos run "labring/cilium:v${cilium_version#v:-1.12.14}" + fi + wait_cluster_ready + sealos run "labring/cert-manager:v${cert_manager_version#v:-1.8.0}" + sealos run "labring/openebs:v${openebs_version#v:-3.4.0}" + kubectl create -f - <