diff --git a/roles/calico/tasks/main.yml b/roles/calico/tasks/main.yml index 75b61f1..82b2f8a 100644 --- a/roles/calico/tasks/main.yml +++ b/roles/calico/tasks/main.yml @@ -63,12 +63,19 @@ # 如果目录下有离线镜像,就把它导入到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' + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'docker'" + + - name: 导入 calico的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ item }}" + with_items: + - "pause_3.1.tar" + - "{{ calico_offline }}" + ignore_errors: true + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'containerd'" # 只需单节点执行一次 - name: 运行 calico网络 diff --git a/roles/cilium/tasks/main.yml b/roles/cilium/tasks/main.yml index 8a7355c..dc2f93c 100644 --- a/roles/cilium/tasks/main.yml +++ b/roles/cilium/tasks/main.yml @@ -54,12 +54,19 @@ # 如果目录下有离线镜像,就把它导入到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' + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'docker'" + + - name: 导入 cilium的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ item }}" + with_items: + - "pause_3.1.tar" + - "{{ cilium_offline }}" + ignore_errors: true + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'containerd'" # 只需单节点执行一次 - name: 运行 cilium网络 diff --git a/roles/cluster-addon/tasks/ingress.yml b/roles/cluster-addon/tasks/ingress.yml index 59ceb59..dce1b85 100644 --- a/roles/cluster-addon/tasks/ingress.yml +++ b/roles/cluster-addon/tasks/ingress.yml @@ -10,8 +10,11 @@ - name: 导入 traefik的离线镜像(若执行失败,可忽略) shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ traefik_offline }}" - when: 'traefik_offline in image_info.stdout' - when: CONTAINER_RUNTIME == 'docker' + when: 'traefik_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入 traefik的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ traefik_offline }}" + when: 'traefik_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - name: 创建 traefik部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/ingress/traefik/traefik-ingress.yaml" @@ -32,8 +35,11 @@ - 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' + when: 'nginx_ingress_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入 nginx_ingress的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ nginx_ingress_offline }}" + when: 'nginx_ingress_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - 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 c332628..a2bfdae 100644 --- a/roles/cluster-addon/tasks/main.yml +++ b/roles/cluster-addon/tasks/main.yml @@ -36,8 +36,11 @@ - 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' + when: 'dns_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入{{ dns_backend }}的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ dns_offline }}" + when: 'dns_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - name: 创建{{ dns_backend }}部署 shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ dns_backend }}" @@ -61,8 +64,11 @@ - 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' + when: 'metricsserver_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入 metrics-server的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ metricsserver_offline }}" + when: 'metricsserver_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - name: 创建 metrics-server部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/metrics-server" @@ -84,8 +90,11 @@ - name: 导入 dashboard的离线镜像(若执行失败,可忽略) shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dashboard_offline }}" - when: 'dashboard_offline in image_info.stdout' - when: CONTAINER_RUNTIME == 'docker' + when: 'dashboard_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入 dashboard的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ dashboard_offline }}" + when: 'dashboard_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - name: 创建 dashboard部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/dashboard && \ @@ -110,8 +119,11 @@ - name: 导入 heapster的离线镜像(若执行失败,可忽略) shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ heapster_offline }}" - when: 'heapster_offline in image_info.stdout' - when: CONTAINER_RUNTIME == 'docker' + when: 'heapster_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入 heapster的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ heapster_offline }}" + when: 'heapster_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - name: 创建 heapster部署 shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/heapster/heapster.yaml" @@ -132,8 +144,11 @@ - name: 导入 metallb的离线镜像(若执行失败,可忽略) shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metallb_offline }}" - when: 'metallb_offline in image_info.stdout' - when: CONTAINER_RUNTIME == 'docker' + when: 'metallb_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入 metallb的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ metallb_offline }}" + when: 'metallb_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - 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 f438ecf..2551767 100644 --- a/roles/flannel/tasks/main.yml +++ b/roles/flannel/tasks/main.yml @@ -45,12 +45,19 @@ # 如果目录下有离线镜像,就把它导入到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' + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'docker'" + + - name: 导入 flannel的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ item }}" + with_items: + - "pause_3.1.tar" + - "{{ flannel_offline }}" + ignore_errors: true + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'containerd'" # 只需单节点执行一次 - name: 运行 flannel网络 diff --git a/roles/kube-router/tasks/main.yml b/roles/kube-router/tasks/main.yml index 877c7ed..4c644d5 100644 --- a/roles/kube-router/tasks/main.yml +++ b/roles/kube-router/tasks/main.yml @@ -61,13 +61,21 @@ # 如果目录下有离线镜像,就把它导入到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' + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'docker'" + + - name: 导入 kube-router的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ item }}" + with_items: + - "pause_3.1.tar" + - "{{ kuberouter_offline }}" + - "{{ busybox_offline }}" + ignore_errors: true + when: "item in image_info.stdout and CONTAINER_RUNTIME == 'containerd'" # 只需单节点执行一次 - name: 运行 kube-router DaemonSet