Skip to content

Commit

Permalink
更新containerd离线镜像导入脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmzj committed May 21, 2019
1 parent bdc4929 commit 9b1ba6e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
11 changes: 9 additions & 2 deletions roles/calico/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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网络
Expand Down
11 changes: 9 additions & 2 deletions roles/cilium/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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网络
Expand Down
14 changes: 10 additions & 4 deletions roles/cluster-addon/tasks/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
35 changes: 25 additions & 10 deletions roles/cluster-addon/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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"
Expand All @@ -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 && \
Expand All @@ -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"
Expand All @@ -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 }}
Expand Down
11 changes: 9 additions & 2 deletions roles/flannel/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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网络
Expand Down
12 changes: 10 additions & 2 deletions roles/kube-router/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b1ba6e

Please sign in to comment.