From a625c99b2ffdd2f232dee9a10f882f53d79d3361 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Sat, 18 May 2019 18:07:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A6=BB=E7=BA=BF=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=8E=A8=E9=80=81=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- down/download.sh | 112 ++++++------------------ roles/calico/tasks/main.yml | 54 ++++++------ roles/cilium/tasks/main.yml | 54 ++++++------ roles/cluster-addon/tasks/ingress.yml | 48 ++++++----- roles/cluster-addon/tasks/main.yml | 120 ++++++++++++++------------ roles/flannel/tasks/main.yml | 50 +++++------ roles/kube-router/tasks/main.yml | 58 +++++++------ 7 files changed, 227 insertions(+), 269 deletions(-) diff --git a/down/download.sh b/down/download.sh index 947084b54..80d6927b8 100644 --- a/down/download.sh +++ b/down/download.sh @@ -7,100 +7,36 @@ K8S_VER=v1.13.4 ETCD_VER=v3.3.8 DOCKER_VER=18.09.2 CNI_VER=v0.7.5 -DOCKER_COMPOSE=1.18.0 -HARBOR=v1.5.4 +DOCKER_COMPOSE_VER=1.18.0 +HARBOR_VER=v1.5.4 +CONTAINERD_VER=1.2.6 -echo "\nNote1: Before this script, please finish downloading binaries manually from following urls." -echo "\nNote2:If binaries are not ready, use `Ctrl + C` to stop this script." +echo -e "\nNote1: Before this script, please finish downloading binaries manually from following urls." +echo -e "\nNote2:If binaries are not ready, use `Ctrl + C` to stop this script." -echo "\n----download k8s binary at:" -echo https://dl.k8s.io/${K8S_VER}/kubernetes-server-linux-amd64.tar.gz +echo -e "\n----download k8s binary at:" +echo -e https://dl.k8s.io/${K8S_VER}/kubernetes-server-linux-amd64.tar.gz -echo "\n----download etcd binary at:" -echo https://github.com/coreos/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -echo https://storage.googleapis.com/etcd/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz +echo -e "\n----download etcd binary at:" +echo -e https://github.com/coreos/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz +echo -e https://storage.googleapis.com/etcd/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -echo "\n----download docker binary at:" -echo https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VER}.tgz +echo -e "\n----download docker binary at:" +echo -e https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VER}.tgz -echo "\n----download ca tools at:" -echo https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -echo https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -echo https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 +echo -e "\n----download ca tools at:" +echo -e https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 +echo -e https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 +echo -e https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -echo "\n----download docker-compose at:" -echo https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE}/docker-compose-Linux-x86_64 +echo -e "\n----download docker-compose at:" +echo -e https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VER}/docker-compose-Linux-x86_64 -echo "\n----download harbor-offline-installer at:" -echo https://storage.googleapis.com/harbor-releases/harbor-offline-installer-${HARBOR}.tgz +echo -e "\n----download harbor-offline-installer at:" +echo -e https://storage.googleapis.com/harbor-releases/harbor-offline-installer-${HARBOR_VER}.tgz -echo "\n----download cni plugins at:" -echo https://github.com/containernetworking/plugins/releases +echo -e "\n----download cni plugins at:" +echo -e https://github.com/containernetworking/plugins/releases -sleep 30 - -### prepare 'cfssl' cert tool suit -echo "\nMoving 'cfssl' to 'bin' dir..." -if [ -f "cfssl_linux-amd64" ]; then - mv -f cfssl_linux-amd64 ../bin/cfssl -else - echo Please download 'cfssl' at 'https://pkg.cfssl.org/R1.2/cfssl_linux-amd64' -fi -if [ -f "cfssljson_linux-amd64" ]; then - mv -f cfssljson_linux-amd64 ../bin/cfssljson -else - echo Please download 'cfssljson' at 'https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64' -fi -if [ -f "cfssl-certinfo_linux-amd64" ]; then - mv -f cfssl-certinfo_linux-amd64 ../bin/cfssl-certinfo -else - echo Please download 'cfssl-certinfo' at 'https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64' -fi - -### prepare 'etcd' binaries -if [ -f "etcd-${ETCD_VER}-linux-amd64.tar.gz" ]; then - echo "\nextracting etcd binaries..." - tar zxf etcd-${ETCD_VER}-linux-amd64.tar.gz - mv -f etcd-${ETCD_VER}-linux-amd64/etcd* ../bin -else - echo Please download 'etcd-${ETCD_VER}-linux-amd64.tar.gz' first -fi - -### prepare kubernetes binaries -if [ -f "kubernetes-server-linux-amd64.tar.gz" ]; then - echo "\nextracting kubernetes binaries..." - tar zxf kubernetes-server-linux-amd64.tar.gz - mv -f kubernetes/server/bin/kube-apiserver ../bin - mv -f kubernetes/server/bin/kube-controller-manager ../bin - mv -f kubernetes/server/bin/kubectl ../bin - mv -f kubernetes/server/bin/kubelet ../bin - mv -f kubernetes/server/bin/kube-proxy ../bin - mv -f kubernetes/server/bin/kube-scheduler ../bin -else - echo Please download 'kubernetes-server-linux-amd64.tar.gz' first -fi - -### prepare docker binaries -if [ -f "docker-${DOCKER_VER}.tgz" ]; then - echo "\nextracting docker binaries..." - tar zxf docker-${DOCKER_VER}.tgz - mv -f docker/docker* ../bin - if [ -f "docker/completion/bash/docker" ]; then - mv -f docker/completion/bash/docker ../roles/docker/files/docker - fi -else - echo Please download 'docker-${DOCKER_VER}.tgz' first -fi - -### prepare cni plugins, needed by flannel; -if [ -f "cni-plugins-amd64-${CNI_VER}.tgz" ]; then - echo "\nextracting cni plugins binaries..." - tar zxf cni-plugins-amd64-${CNI_VER}.tgz - mv -f bridge ../bin - mv -f flannel ../bin - mv -f host-local ../bin - mv -f loopback ../bin - mv -f portmap ../bin -else - echo Please download 'cni-plugins-amd64-${CNI_VER}.tgz' first -fi +echo -e "\n----download containerd at:" +echo -e https://storage.googleapis.com/cri-containerd-release/cri-containerd-${CONTAINERD_VER}.linux-amd64.tar.gz diff --git a/roles/calico/tasks/main.yml b/roles/calico/tasks/main.yml index 7136e426c..75b61f152 100644 --- a/roles/calico/tasks/main.yml +++ b/roles/calico/tasks/main.yml @@ -33,12 +33,6 @@ delegate_to: "{{ groups.deploy[0] }}" run_once: true -- name: 检查是否已下载离线calico镜像 - command: "ls {{ base_dir }}/down" - register: download_info - connection: local - run_once: true - - name: node 节点创建calico 相关目录 file: name={{ item }} state=directory with_items: @@ -47,26 +41,34 @@ - /opt/kube/images # 【可选】推送离线docker 镜像,可以忽略执行错误 -- name: 尝试推送离线docker 镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} - when: 'item in download_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ calico_offline }}" - ignore_errors: true - -- name: 获取calico离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - -# 如果目录下有离线镜像,就把它导入到node节点上 -- name: 导入 calico的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" - when: 'item in image_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ calico_offline }}" - ignore_errors: true +- block: + - name: 检查是否已下载离线calico镜像 + command: "ls {{ base_dir }}/down" + register: download_info + connection: local + run_once: true + + - name: 尝试推送离线docker 镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} + when: 'item in download_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ calico_offline }}" + ignore_errors: true + + - name: 获取calico离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + # 如果目录下有离线镜像,就把它导入到node节点上 + - name: 导入 calico的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" + when: 'item in image_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ calico_offline }}" + ignore_errors: true + when: CONTAINER_RUNTIME == 'docker' # 只需单节点执行一次 - name: 运行 calico网络 diff --git a/roles/cilium/tasks/main.yml b/roles/cilium/tasks/main.yml index 6f9d9169c..8a7355c29 100644 --- a/roles/cilium/tasks/main.yml +++ b/roles/cilium/tasks/main.yml @@ -17,12 +17,6 @@ fail: msg="kernel {{ ansible_kernel }} is too old for cilium installing" when: "KERNEL_VER|float <= 4.09" -- name: 检查是否已下载离线cilium镜像 - command: "ls {{ base_dir }}/down" - register: download_info - connection: local - run_once: true - - name: node 节点创建cilium 相关目录 file: name={{ item }} state=directory with_items: @@ -38,26 +32,34 @@ state: "mounted" # 【可选】推送离线docker 镜像,可以忽略执行错误 -- name: 尝试推送离线docker 镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} - when: 'item in download_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ cilium_offline }}" - ignore_errors: true - -- name: 获取cilium离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - -# 如果目录下有离线镜像,就把它导入到node节点上 -- name: 导入 cilium的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" - when: 'item in image_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ cilium_offline }}" - ignore_errors: true +- block: + - name: 检查是否已下载离线cilium镜像 + command: "ls {{ base_dir }}/down" + register: download_info + connection: local + run_once: true + + - name: 尝试推送离线docker 镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} + when: 'item in download_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ cilium_offline }}" + ignore_errors: true + + - name: 获取cilium离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + # 如果目录下有离线镜像,就把它导入到node节点上 + - name: 导入 cilium的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" + when: 'item in image_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ cilium_offline }}" + ignore_errors: true + when: CONTAINER_RUNTIME == 'docker' # 只需单节点执行一次 - name: 运行 cilium网络 diff --git a/roles/cluster-addon/tasks/ingress.yml b/roles/cluster-addon/tasks/ingress.yml index aa658db72..59ceb5929 100644 --- a/roles/cluster-addon/tasks/ingress.yml +++ b/roles/cluster-addon/tasks/ingress.yml @@ -1,15 +1,17 @@ - block: - - name: 尝试推送离线 traefik镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ traefik_offline }} dest=/opt/kube/images/{{ traefik_offline }} - when: 'traefik_offline in download_info.stdout' - - - name: 获取traefik离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入 traefik的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ traefik_offline }}" - when: 'traefik_offline in image_info.stdout' + - block: + - name: 尝试推送离线 traefik镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ traefik_offline }} dest=/opt/kube/images/{{ traefik_offline }} + when: 'traefik_offline in download_info.stdout' + + - name: 获取traefik离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入 traefik的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ traefik_offline }}" + when: 'traefik_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 创建 traefik部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/ingress/traefik/traefik-ingress.yaml" @@ -19,17 +21,19 @@ ignore_errors: true - block: - - name: 尝试推送离线 nginx-ingress镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ nginx_ingress_offline }} dest=/opt/kube/images/{{ nginx_ingress_offline }} - when: 'nginx_ingress_offline in download_info.stdout' - - - name: 获取nginx_ingress离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入 nginx_ingress的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ nginx_ingress_offline }}" - when: 'nginx_ingress_offline in image_info.stdout' + - block: + - name: 尝试推送离线 nginx-ingress镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ nginx_ingress_offline }} dest=/opt/kube/images/{{ nginx_ingress_offline }} + when: 'nginx_ingress_offline in download_info.stdout' + + - name: 获取nginx_ingress离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入 nginx_ingress的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ nginx_ingress_offline }}" + when: 'nginx_ingress_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 创建 nginx_ingress部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/ingress/nginx-ingress/nginx-ingress.yaml" diff --git a/roles/cluster-addon/tasks/main.yml b/roles/cluster-addon/tasks/main.yml index d3705004a..c3326285f 100644 --- a/roles/cluster-addon/tasks/main.yml +++ b/roles/cluster-addon/tasks/main.yml @@ -25,17 +25,19 @@ run_once: true - block: - - name: 尝试推送离线{{ dns_backend }}镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ dns_offline }} dest=/opt/kube/images/{{ dns_offline }} - when: 'dns_offline in download_info.stdout' - - - name: 获取{{ dns_backend }}离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入{{ dns_backend }}的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dns_offline }}" - when: 'dns_offline in image_info.stdout' + - block: + - name: 尝试推送离线{{ dns_backend }}镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ dns_offline }} dest=/opt/kube/images/{{ dns_offline }} + when: 'dns_offline in download_info.stdout' + + - name: 获取{{ dns_backend }}离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入{{ dns_backend }}的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dns_offline }}" + when: 'dns_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 创建{{ dns_backend }}部署 shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ dns_backend }}" @@ -48,17 +50,19 @@ ignore_errors: true - block: - - name: 尝试推送离线 metrics-server镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ metricsserver_offline }} dest=/opt/kube/images/{{ metricsserver_offline }} - when: 'metricsserver_offline in download_info.stdout' - - - name: 获取metrics-server离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入 metrics-server的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metricsserver_offline }}" - when: 'metricsserver_offline in image_info.stdout' + - block: + - name: 尝试推送离线 metrics-server镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ metricsserver_offline }} dest=/opt/kube/images/{{ metricsserver_offline }} + when: 'metricsserver_offline in download_info.stdout' + + - name: 获取metrics-server离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入 metrics-server的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metricsserver_offline }}" + when: 'metricsserver_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 创建 metrics-server部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/metrics-server" @@ -69,17 +73,19 @@ # 现阶段 dashboard 获取metrics仍旧依赖于heapster,因此需连带安装heapster - block: - - name: 尝试推送离线 dashboard镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ dashboard_offline }} dest=/opt/kube/images/{{ dashboard_offline }} - when: 'dashboard_offline in download_info.stdout' - - - name: 获取dashboard离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入 dashboard的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dashboard_offline }}" - when: 'dashboard_offline in image_info.stdout' + - block: + - name: 尝试推送离线 dashboard镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ dashboard_offline }} dest=/opt/kube/images/{{ dashboard_offline }} + when: 'dashboard_offline in download_info.stdout' + + - name: 获取dashboard离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入 dashboard的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dashboard_offline }}" + when: 'dashboard_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 创建 dashboard部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/dashboard && \ @@ -93,17 +99,19 @@ when: '"ingress-controller" not in pod_info.stdout and ingress_install == "yes"' - block: - - name: 尝试推送离线 heapster镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ heapster_offline }} dest=/opt/kube/images/{{ heapster_offline }} - when: 'heapster_offline in download_info.stdout' - - - name: 获取heapster离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入 heapster的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ heapster_offline }}" - when: 'heapster_offline in image_info.stdout' + - block: + - name: 尝试推送离线 heapster镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ heapster_offline }} dest=/opt/kube/images/{{ heapster_offline }} + when: 'heapster_offline in download_info.stdout' + + - name: 获取heapster离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入 heapster的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ heapster_offline }}" + when: 'heapster_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 创建 heapster部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/heapster/heapster.yaml" @@ -113,17 +121,19 @@ ignore_errors: true - block: - - name: 尝试推送离线 metallb镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ metallb_offline }} dest=/opt/kube/images/{{ metallb_offline }} - when: 'metallb_offline in download_info.stdout' - - - name: 获取metallb离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - - - name: 导入 metallb的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metallb_offline }}" - when: 'metallb_offline in image_info.stdout' + - block: + - name: 尝试推送离线 metallb镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ metallb_offline }} dest=/opt/kube/images/{{ metallb_offline }} + when: 'metallb_offline in download_info.stdout' + + - name: 获取metallb离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入 metallb的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metallb_offline }}" + when: 'metallb_offline in image_info.stdout' + when: CONTAINER_RUNTIME == 'docker' - name: 生成 metallb 相关 manifests template: src=metallb/{{ item }}.j2 dest=/opt/kube/kube-system/{{ item }} diff --git a/roles/flannel/tasks/main.yml b/roles/flannel/tasks/main.yml index b22e6e152..f438ecfe1 100644 --- a/roles/flannel/tasks/main.yml +++ b/roles/flannel/tasks/main.yml @@ -7,12 +7,6 @@ delegate_to: "{{ groups.deploy[0] }}" run_once: true -- name: 检查是否已下载离线flannel镜像 - command: "ls {{ base_dir }}/down" - register: download_info - connection: local - run_once: true - - name: 创建flannel cni 相关目录 file: name={{ item }} state=directory with_items: @@ -29,26 +23,34 @@ - portmap # 【可选】推送离线docker 镜像,可以忽略执行错误 -- name: 尝试推送离线docker 镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} - when: 'item in download_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ flannel_offline }}" - ignore_errors: true +- block: + - name: 检查是否已下载离线flannel镜像 + command: "ls {{ base_dir }}/down" + register: download_info + connection: local + run_once: true + + - name: 尝试推送离线docker 镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} + when: 'item in download_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ flannel_offline }}" + ignore_errors: true -- name: 获取flannel离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info + - name: 获取flannel离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info -# 如果目录下有离线镜像,就把它导入到node节点上 -- name: 导入 flannel的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" - when: 'item in image_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ flannel_offline }}" - ignore_errors: true + # 如果目录下有离线镜像,就把它导入到node节点上 + - name: 导入 flannel的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" + when: 'item in image_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ flannel_offline }}" + ignore_errors: true + when: CONTAINER_RUNTIME == 'docker' # 只需单节点执行一次 - name: 运行 flannel网络 diff --git a/roles/kube-router/tasks/main.yml b/roles/kube-router/tasks/main.yml index ffd243621..877c7edd9 100644 --- a/roles/kube-router/tasks/main.yml +++ b/roles/kube-router/tasks/main.yml @@ -12,12 +12,6 @@ delegate_to: "{{ groups.deploy[0] }}" run_once: true -- name: 检查是否已下载离线kube-router镜像 - command: "ls {{ base_dir }}/down" - register: download_info - connection: local - run_once: true - - name: 创建cni 和kube-router 相关目录 file: name={{ item }} state=directory with_items: @@ -44,28 +38,36 @@ ignore_errors: true # 【可选】推送离线docker 镜像,可以忽略执行错误 -- name: 尝试推送离线docker 镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} - when: 'item in download_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ kuberouter_offline }}" - - "{{ busybox_offline }}" - ignore_errors: true - -- name: 获取kube-router离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - -# 如果目录下有离线镜像,就把它导入到node节点上 -- name: 导入 kube-router的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" - when: 'item in image_info.stdout' - with_items: - - "pause_3.1.tar" - - "{{ kuberouter_offline }}" - - "{{ busybox_offline }}" - ignore_errors: true +- block: + - name: 检查是否已下载离线kube-router镜像 + command: "ls {{ base_dir }}/down" + register: download_info + connection: local + run_once: true + + - name: 尝试推送离线docker 镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }} + when: 'item in download_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ kuberouter_offline }}" + - "{{ busybox_offline }}" + ignore_errors: true + + - name: 获取kube-router离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + # 如果目录下有离线镜像,就把它导入到node节点上 + - name: 导入 kube-router的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}" + when: 'item in image_info.stdout' + with_items: + - "pause_3.1.tar" + - "{{ kuberouter_offline }}" + - "{{ busybox_offline }}" + ignore_errors: true + when: CONTAINER_RUNTIME == 'docker' # 只需单节点执行一次 - name: 运行 kube-router DaemonSet