离线安装单节点 Rancher 2.5.11

参考 Rancher 中文网官方链接

1. 基础环境

  • 基础环境配置需要关闭防火墙、SELinux、安装 Docker 等,可以参考我之前很多笔记中都有,在此不再记录。
  • 需要离线环境有 Harbor 私有仓库服务,也可以参考我之前写过的教程进行搭建。

2. 拉取 Rancher 所需镜像

官方提供有拉取所有所需镜像的脚本文件,但是拉取速度很慢,镜像数量较多,建议使用国内阿里云拉取。

  1. 下载拉取镜像脚本 rancher-save-images.sh 脚本地址(支持阿里云仓库)

    #!/bin/bash
    list="rancher-images.txt"
    images="rancher-images.tar.gz"
    
    usage () {
        echo "USAGE: $0 [--image-list rancher-images.txt] [--images rancher-images.tar.gz] [--from-aliyun true]"
        echo "  [-l|--image-list path] text file with list of images; one image per line."
        echo "  [-i|--images path] tar.gz generated by docker save."
        echo "  [--from-aliyun true|false] get an image from aliyun"
        echo "  [-h|--help] Usage message"
    }
    
    POSITIONAL=()
    while [[ $# -gt 0 ]]; do
        key="$1"
        case $key in
            -i|--images)
            images="$2"
            shift # past argument
            shift # past value
            ;;
            -l|--image-list)
            list="$2"
            shift # past argument
            shift # past value
            ;;
            --from-aliyun)
            from_aliyun="$2"
            shift # past argument
            shift # past value
            ;;
            -h|--help)
            help="true"
            shift
            ;;
            *)
            usage
            exit 1
            ;;
        esac
    done
    
    if [[ $help ]]; then
        usage
        exit 0
    fi
    
    pulled=""
    while IFS= read -r i; do
        [ -z "${i}" ] && continue
        aliyun_repo="registry.cn-hangzhou.aliyuncs.com"
        delimiter_num=$(echo ${i} |  awk -F'/' '{print NF-1}')
        if [[ ${from_aliyun} == "true" ]]; then
            case ${delimiter_num} in
                0)
                i="${aliyun_repo}/rancher/${i}"
                ;;
                1)
                i="${aliyun_repo}/${i}"
                ;;
            esac
        fi
        if docker pull "${i}" > /dev/null 2>&1; then
            echo "Image pull success: ${i}"
            if [[ ${from_aliyun} == "true" ]]; then
                case ${delimiter_num} in
                    0)
                    docker_i=$(echo ${i#*/*/})
                    ;;
                    1)
                    docker_i=$(echo ${i#*/})
                    ;;
                    *)
                    docker_i=${i}
                    ;;
                esac            
                docker tag ${i} ${docker_i}
                i=${docker_i}
            fi
            pulled="${pulled} ${i}"
        else
            if docker inspect "${i}" > /dev/null 2>&1; then
                pulled="${pulled} ${i}"		
            else
                echo "Image pull failed: ${i}"
            fi
        fi
    done < "${list}"
    
    echo "Creating ${images} with $(echo ${pulled} | wc -w | tr -d '[:space:]') images"
    docker save $(echo ${pulled}) | gzip --stdout > ${images}
    
  2. 下载镜像列表文件 rancher-images.txt

    busybox
    rancher/backup-restore-operator:v1.2.0
    rancher/cis-operator:v1.0.6
    rancher/configmap-reload:v0.3.0-rancher4
    rancher/coredns-coredns:1.6.2
    rancher/coredns-coredns:1.6.9
    rancher/coredns-coredns:1.8.3
    rancher/coreos-flannel:v0.13.0-rancher1
    rancher/coreos-kube-state-metrics:v1.9.7
    rancher/coreos-prometheus-config-reloader:v0.39.0
    rancher/coreos-prometheus-operator:v0.39.0
    rancher/eks-operator:v1.0.10
    rancher/externalip-webhook:v0.1.6
    rancher/flannel-cni:v0.3.0-rancher6
    rancher/fleet-agent:v0.3.5
    rancher/fleet:v0.3.5
    rancher/fluent-bit:1.6.10
    rancher/fluentd:v0.1.30
    rancher/gitjob:v0.1.15
    rancher/gke-operator:v1.1.1
    rancher/grafana-grafana:6.7.4
    rancher/grafana-grafana:7.1.5
    rancher/hyperkube:v1.17.17-rancher2
    rancher/hyperkube:v1.18.20-rancher1
    rancher/hyperkube:v1.19.16-rancher1
    rancher/hyperkube:v1.20.12-rancher1
    rancher/istio-1.5-migration:0.1.1
    rancher/istio-citadel:1.5.9
    rancher/istio-coredns-plugin:0.2-istio-1.1
    rancher/istio-galley:1.5.9
    rancher/istio-installer:1.9.8-rancher1
    rancher/istio-kubectl:1.4.6
    rancher/istio-kubectl:1.5.10
    rancher/istio-kubectl:1.5.9
    rancher/istio-mixer:1.5.9
    rancher/istio-node-agent-k8s:1.5.9
    rancher/istio-pilot:1.5.9
    rancher/istio-proxyv2:1.5.9
    rancher/istio-sidecar_injector:1.5.9
    rancher/jaegertracing-all-in-one:1.14
    rancher/jetstack-cert-manager-controller:v0.8.1
    rancher/jimmidyson-configmap-reload:v0.3.0
    rancher/k3s-upgrade:v1.17.17-k3s1
    rancher/k3s-upgrade:v1.18.20-k3s1
    rancher/k3s-upgrade:v1.19.15-k3s2
    rancher/k3s-upgrade:v1.20.11-k3s2
    rancher/kiali-kiali:v1.17
    rancher/klipper-helm:v0.2.3
    rancher/klipper-helm:v0.4.3
    rancher/klipper-helm:v0.6.4-build20210813
    rancher/klipper-lb:v0.1.2
    rancher/klipper-lb:v0.2.0
    rancher/kube-api-auth:v0.1.4
    rancher/kubectl:v1.18.0
    rancher/kubectl:v1.20.2
    rancher/kubernetes-external-dns:v0.7.3
    rancher/library-busybox:1.32.1
    rancher/library-traefik:1.7.19
    rancher/local-path-provisioner:v0.0.11
    rancher/local-path-provisioner:v0.0.14
    rancher/local-path-provisioner:v0.0.19
    rancher/log-aggregator:v0.1.8
    rancher/metrics-server:v0.3.6
    rancher/mirrored-banzaicloud-fluentd:v1.11.5-alpine-12
    rancher/mirrored-banzaicloud-logging-operator:3.9.4
    rancher/mirrored-calico-cni:v3.13.4
    rancher/mirrored-calico-cni:v3.16.5
    rancher/mirrored-calico-cni:v3.17.2
    rancher/mirrored-calico-ctl:v3.13.4
    rancher/mirrored-calico-ctl:v3.16.5
    rancher/mirrored-calico-ctl:v3.17.2
    rancher/mirrored-calico-kube-controllers:v3.13.4
    rancher/mirrored-calico-kube-controllers:v3.16.5
    rancher/mirrored-calico-kube-controllers:v3.17.2
    rancher/mirrored-calico-node:v3.13.4
    rancher/mirrored-calico-node:v3.16.5
    rancher/mirrored-calico-node:v3.17.2
    rancher/mirrored-calico-pod2daemon-flexvol:v3.13.4
    rancher/mirrored-calico-pod2daemon-flexvol:v3.16.5
    rancher/mirrored-calico-pod2daemon-flexvol:v3.17.2
    rancher/mirrored-cloud-provider-vsphere-cpi-release-manager:v1.18.0
    rancher/mirrored-cloud-provider-vsphere-cpi-release-manager:v1.19.0
    rancher/mirrored-cloud-provider-vsphere-cpi-release-manager:v1.20.0
    rancher/mirrored-cloud-provider-vsphere-cpi-release-manager:v1.21.0
    rancher/mirrored-cloud-provider-vsphere-csi-release-driver:v2.3.0
    rancher/mirrored-cloud-provider-vsphere-csi-release-syncer:v2.3.0
    rancher/mirrored-cluster-proportional-autoscaler:1.7.1
    rancher/mirrored-cluster-proportional-autoscaler:1.8.1
    rancher/mirrored-coredns-coredns:1.6.5
    rancher/mirrored-coredns-coredns:1.6.9
    rancher/mirrored-coredns-coredns:1.7.0
    rancher/mirrored-coredns-coredns:1.8.0
    rancher/mirrored-coreos-etcd:v3.4.15-rancher1
    rancher/mirrored-coreos-etcd:v3.4.3-rancher1
    rancher/mirrored-coreos-flannel:v0.12.0
    rancher/mirrored-coreos-flannel:v0.13.0
    rancher/mirrored-curlimages-curl:7.77.0
    rancher/mirrored-directxman12-k8s-prometheus-adapter:v0.8.4
    rancher/mirrored-fluent-fluent-bit:1.6.10
    rancher/mirrored-fluent-fluent-bit:1.6.10-debug
    rancher/mirrored-grafana-grafana-image-renderer:3.0.1
    rancher/mirrored-grafana-grafana:7.5.8
    rancher/mirrored-idealista-prom2teams:3.2.1
    rancher/mirrored-ingress-nginx-kube-webhook-certgen:v1.1.1
    rancher/mirrored-istio-install-cni:1.9.8
    rancher/mirrored-istio-pilot:1.9.8
    rancher/mirrored-istio-proxyv2:1.9.8
    rancher/mirrored-jaegertracing-all-in-one:1.20.0
    rancher/mirrored-jenkins-jnlp-slave:3.35-4
    rancher/mirrored-jettech-kube-webhook-certgen:v1.5.2
    rancher/mirrored-jimmidyson-configmap-reload:v0.4.0
    rancher/mirrored-k8s-dns-dnsmasq-nanny:1.15.0
    rancher/mirrored-k8s-dns-dnsmasq-nanny:1.15.10
    rancher/mirrored-k8s-dns-dnsmasq-nanny:1.15.2
    rancher/mirrored-k8s-dns-kube-dns:1.15.0
    rancher/mirrored-k8s-dns-kube-dns:1.15.10
    rancher/mirrored-k8s-dns-kube-dns:1.15.2
    rancher/mirrored-k8s-dns-node-cache:1.15.13
    rancher/mirrored-k8s-dns-node-cache:1.15.7
    rancher/mirrored-k8s-dns-sidecar:1.15.0
    rancher/mirrored-k8s-dns-sidecar:1.15.10
    rancher/mirrored-k8s-dns-sidecar:1.15.2
    rancher/mirrored-k8scsi-csi-node-driver-registrar:v2.1.0
    rancher/mirrored-k8scsi-csi-resizer:v1.1.0
    rancher/mirrored-k8scsi-livenessprobe:v2.2.0
    rancher/mirrored-kiali-kiali:v1.32.0
    rancher/mirrored-kiwigrid-k8s-sidecar:1.12.2
    rancher/mirrored-kube-rbac-proxy:v0.5.0
    rancher/mirrored-kube-state-metrics-kube-state-metrics:v2.0.0
    rancher/mirrored-library-busybox:1.31.1
    rancher/mirrored-library-nginx:1.19.9-alpine
    rancher/mirrored-library-nginx:1.21.1-alpine
    rancher/mirrored-longhornio-backing-image-manager:v2_20210820
    rancher/mirrored-longhornio-csi-attacher:v3.2.1
    rancher/mirrored-longhornio-csi-node-driver-registrar:v2.3.0
    rancher/mirrored-longhornio-csi-provisioner:v2.1.2
    rancher/mirrored-longhornio-csi-resizer:v1.2.0
    rancher/mirrored-longhornio-csi-snapshotter:v3.0.3
    rancher/mirrored-longhornio-longhorn-engine:v1.2.2
    rancher/mirrored-longhornio-longhorn-instance-manager:v1_20210731
    rancher/mirrored-longhornio-longhorn-manager:v1.2.2
    rancher/mirrored-longhornio-longhorn-share-manager:v1_20210914
    rancher/mirrored-longhornio-longhorn-ui:v1.2.2
    rancher/mirrored-messagebird-sachet:0.2.3
    rancher/mirrored-metrics-server:v0.3.6
    rancher/mirrored-metrics-server:v0.4.1
    rancher/mirrored-minio-minio:RELEASE.2020-07-13T18-09-56Z
    rancher/mirrored-nginx-ingress-controller-defaultbackend:1.5-rancher1
    rancher/mirrored-openpolicyagent-gatekeeper:v3.3.0
    rancher/mirrored-pause:3.1
    rancher/mirrored-pause:3.2
    rancher/mirrored-plugins-docker:18.09
    rancher/mirrored-prometheus-alertmanager:v0.22.2
    rancher/mirrored-prometheus-node-exporter:v1.1.2
    rancher/mirrored-prometheus-operator-prometheus-config-reloader:v0.48.0
    rancher/mirrored-prometheus-operator-prometheus-operator:v0.48.0
    rancher/mirrored-prometheus-prometheus:v2.27.1
    rancher/mirrored-sig-storage-csi-attacher:v3.2.0
    rancher/mirrored-sig-storage-csi-provisioner:v2.2.0
    rancher/mirrored-sonobuoy-sonobuoy:v0.53.2
    rancher/nginx-ingress-controller:nginx-0.35.0-rancher2
    rancher/nginx-ingress-controller:nginx-0.49.3-rancher1
    rancher/opa-gatekeeper:v3.1.0-beta.7
    rancher/openzipkin-zipkin:2.14.2
    rancher/pause:3.1
    rancher/pipeline-jenkins-server:v0.1.4
    rancher/pipeline-tools:v0.1.15
    rancher/prom-alertmanager:v0.21.0
    rancher/prom-node-exporter:v1.0.1
    rancher/prom-prometheus:v2.12.0
    rancher/prom-prometheus:v2.18.2
    rancher/prometheus-auth:v0.2.1
    rancher/pstauffer-curl:v1.0.3
    rancher/pushprox-client:v0.1.0-rancher2-client
    rancher/pushprox-proxy:v0.1.0-rancher2-proxy
    rancher/rancher-agent:v2.5.11
    rancher/rancher-operator:v0.1.4
    rancher/rancher-runtime:v2.5.11
    rancher/rancher-webhook:v0.1.2
    rancher/rancher:v2.5.11
    rancher/rke-tools:v0.1.74
    rancher/rke-tools:v0.1.75
    rancher/rke-tools:v0.1.78
    rancher/security-scan:v0.1.14
    rancher/security-scan:v0.2.4
    rancher/shell:v0.1.6
    rancher/shell:v0.1.8
    rancher/sonobuoy-sonobuoy:v0.16.3
    rancher/system-upgrade-controller:v0.6.2
    rancher/tekton-utils:v0.1.1
    rancher/thanosio-thanos:v0.15.0
    rancher/webhook-receiver:v0.2.4
    registry:2
    
  3. 在具有外网环境服务器执行该脚本

    # 赋予执行权限
    chmod +x rancher-save-images.sh
    
    # 执行脚本,并指定从阿里云镜像仓库拉取
    ./rancher-save-images.sh --image-list ./rancher-images.txt --from-aliyun true
    

    拉取过程如截图,很慢,耐心等待…离线安装单节点 Rancher 2.5.11_第1张图片
    拉取完成后会进行压缩打包,很慢,耐心等待…
    离线安装单节点 Rancher 2.5.11_第2张图片

3. 推送 Rancher 所需镜像至私有仓库

  1. 下载推送镜像脚本 rancher-load-images.sh 脚本地址(支持阿里云仓库)

    #!/bin/bash
    images="rancher-images.tar.gz"
    list="rancher-images.txt"
    windows_image_list=""
    windows_versions="1809"
    usage () {
        echo "USAGE: $0 [--images rancher-images.tar.gz] --registry my.registry.com:5000"
        echo "  [-l|--image-list path] text file with list of images; one image per line."
        echo "  [-i|--images path] tar.gz generated by docker save."
        echo "  [-r|--registry registry:port] target private registry:port."
        echo "  [--windows-image-list path] text file with list of images used in Windows. Windows image mirroring is skipped when this is empty"
        echo "  [--windows-versions version] Comma separated Windows versions. e.g., \"1809,2004,20H2\". (Default \"1809\")"
        echo "  [-h|--help] Usage message"
    }
    
    push_manifest () {
        export DOCKER_CLI_EXPERIMENTAL=enabled
        manifest_list=()
        for i in "${arch_list[@]}"
        do
            manifest_list+=("$1-${i}")
        done
    
        echo "Preparing manifest $1, list[${arch_list[@]}]"
        docker manifest create "$1" "${manifest_list[@]}" --amend
        docker manifest push "$1" --purge
    }
    
    while [[ $# -gt 0 ]]; do
        key="$1"
        case $key in
            -r|--registry)
            reg="$2"
            shift # past argument
            shift # past value
            ;;
            -l|--image-list)
            list="$2"
            shift # past argument
            shift # past value
            ;;
            -i|--images)
            images="$2"
            shift # past argument
            shift # past value
            ;;
            --windows-image-list)
            windows_image_list="$2"
            shift # past argument
            shift # past value
            ;;
            --windows-versions)
            windows_versions="$2"
            shift # past argument
            shift # past value
            ;;
            -h|--help)
            help="true"
            shift
            ;;
            *)
            usage
            exit 1
            ;;
        esac
    done
    if [[ -z $reg ]]; then
        usage
        exit 1
    fi
    if [[ $help ]]; then
        usage
        exit 0
    fi
    
    docker load --input ${images}
    
    linux_images=()
    while IFS= read -r i; do
        [ -z "${i}" ] && continue
        linux_images+=("${i}");
    done < "${list}"
    
    arch_list=()
    if [[ -n "${windows_image_list}" ]]; then
        IFS=',' read -r -a versions <<< "$windows_versions"
        for version in "${versions[@]}"
        do
            arch_list+=("windows-${version}")
        done
    
        windows_images=()
        while IFS= read -r i; do
            [ -z "${i}" ] && continue
            windows_images+=("${i}")
        done < "${windows_image_list}"
    
        # use manifest to publish images only used in Windows
        for i in "${windows_images[@]}"; do
            if [[ ! " ${linux_images[@]}" =~ " ${i}" ]]; then
                case $i in
                */*)
                    image_name="${reg}/${i}"
                    ;;
                *)
                    image_name="${reg}/rancher/${i}"
                    ;;
                esac
                push_manifest "${image_name}"
            fi
        done
    fi
    
    
    arch_list+=("linux-amd64")
    for i in "${linux_images[@]}"; do
        [ -z "${i}" ] && continue
        arch_suffix=""
        use_manifest=false
        if [[ (-n "${windows_image_list}") && " ${windows_images[@]}" =~ " ${i}" ]]; then
            # use manifest to publish images when it is used both in Linux and Windows
            use_manifest=true
            arch_suffix="-linux-amd64"
        fi
        case $i in
        */*)
            image_name="${reg}/${i}"
            ;;
        *)
            image_name="${reg}/rancher/${i}"
            ;;
        esac
    
        docker tag "${i}" "${image_name}${arch_suffix}"
        docker push "${image_name}${arch_suffix}"
    
        if $use_manifest; then
            push_manifest "${image_name}"
        fi
    done
    
  2. 执行推送镜像脚本

    # 赋予执行权限
    chmod +x rancher-load-images.sh
    
    # 执行脚本,其中 192.168.1.10:80 是我的私有仓库地址及端口号
    ./rancher-load-images.sh --image-list ./rancher-images.txt --registry 192.168.1.10:80
    

    推送完成后,可以在私有仓库看到结果离线安装单节点 Rancher 2.5.11_第3张图片

你可能感兴趣的:(服务器运维,Rancher,docker,容器,kubernetes)