From e51aa3603dd4afae26d615380e76a3c236e6d6dc Mon Sep 17 00:00:00 2001 From: gjmzj Date: Tue, 19 Jan 2021 20:20:05 +0800 Subject: [PATCH] =?UTF-8?q?fix=20nodelocaldns=20=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playbooks/22.addnode.yml | 5 ++--- roles/cluster-addon/tasks/nodelocaldns.yml | 16 --------------- roles/cluster-addon/vars/main.yml | 2 -- roles/kube-node/tasks/main.yml | 24 ++++++++++++++++++++++ roles/kube-node/vars/main.yml | 3 +++ 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/playbooks/22.addnode.yml b/playbooks/22.addnode.yml index c3197b7..158ff5d 100644 --- a/playbooks/22.addnode.yml +++ b/playbooks/22.addnode.yml @@ -17,7 +17,6 @@ copy: src={{ item }} dest=/opt/kube/images/ with_fileglob: - "{{ base_dir }}/down/coredns*.tar" - - "{{ base_dir }}/down/k8s-dns-node-cache*.tar" - "{{ base_dir }}/down/dashboard*.tar" - "{{ base_dir }}/down/metrics-scraper*.tar" - "{{ base_dir }}/down/metrics-server*.tar" @@ -25,11 +24,11 @@ ignore_errors: true - name: 导入离线镜像(若执行失败,可忽略) - shell: ls /opt/kube/images/*.tar |while read n;do {{ bin_dir }}/docker load -i $n ;done + shell: "for image in $(echo /opt/kube/images/*.tar); do {{ bin_dir }}/docker load -i $image; done;" ignore_errors: true when: "CONTAINER_RUNTIME == 'docker'" - name: 导入离线镜像(若执行失败,可忽略) - shell: ls /opt/kube/images/*.tar |while read n;do {{ bin_dir }}/ctr -n=k8s.io images import $n ;done + shell: "for image in $(echo /opt/kube/images/*.tar); do {{ bin_dir }}/ctr -n=k8s.io images import $image; done;" ignore_errors: true when: "CONTAINER_RUNTIME == 'containerd'" diff --git a/roles/cluster-addon/tasks/nodelocaldns.yml b/roles/cluster-addon/tasks/nodelocaldns.yml index aab12e5..9b3697b 100644 --- a/roles/cluster-addon/tasks/nodelocaldns.yml +++ b/roles/cluster-addon/tasks/nodelocaldns.yml @@ -1,19 +1,3 @@ -- name: 尝试推送离线dnscache镜像(若执行失败,可忽略) - copy: src={{ base_dir }}/down/{{ dnscache_offline }} dest=/opt/kube/images/{{ dnscache_offline }} - when: 'dnscache_offline in download_info.stdout' - -- name: 获取dnscache离线镜像推送情况 - command: "ls /opt/kube/images" - register: image_info - -- name: 导入dnscache的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dnscache_offline }}" - when: 'dnscache_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' - -- name: 导入dnscache的离线镜像(若执行失败,可忽略) - shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ dnscache_offline }}" - when: 'dnscache_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' - - name: 准备dnscache的部署文件 template: src=dns/nodelocaldns-ipvs.yaml.j2 dest={{ cluster_dir }}/yml/nodelocaldns.yaml when: "PROXY_MODE == 'ipvs'" diff --git a/roles/cluster-addon/vars/main.yml b/roles/cluster-addon/vars/main.yml index 3d7a5b8..7235d76 100644 --- a/roles/cluster-addon/vars/main.yml +++ b/roles/cluster-addon/vars/main.yml @@ -4,8 +4,6 @@ CLUSTER_DNS_SVC_IP: "{{ SERVICE_CIDR | ipaddr('net') | ipaddr(2) | ipaddr('addre # coredns_offline: "coredns_{{ corednsVer }}.tar" -dnscache_offline: "k8s-dns-node-cache_{{ dnsNodeCacheVer }}.tar" - metricsserver_offline: "metrics-server_{{ metricsVer }}.tar" dashboard_offline: "dashboard_{{ dashboardVer }}.tar" diff --git a/roles/kube-node/tasks/main.yml b/roles/kube-node/tasks/main.yml index 437e099..465b50e 100644 --- a/roles/kube-node/tasks/main.yml +++ b/roles/kube-node/tasks/main.yml @@ -101,3 +101,27 @@ - name: 设置node节点role shell: "{{ bin_dir }}/kubectl label node {{ inventory_hostname }} kubernetes.io/role=node --overwrite" ignore_errors: true + +- block: + - name: 获取已下载离线镜像信息 + command: "ls {{ base_dir }}/down" + register: download_info + connection: local + run_once: true + + - name: 尝试推送离线dnscache镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ dnscache_offline }} dest=/opt/kube/images/{{ dnscache_offline }} + when: 'dnscache_offline in download_info.stdout' + + - name: 获取dnscache离线镜像推送情况 + command: "ls /opt/kube/images" + register: image_info + + - name: 导入dnscache的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dnscache_offline }}" + when: 'dnscache_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"' + + - name: 导入dnscache的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ dnscache_offline }}" + when: 'dnscache_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"' + when: "ENABLE_LOCAL_DNS_CACHE|bool" diff --git a/roles/kube-node/vars/main.yml b/roles/kube-node/vars/main.yml index c8933ac..03d788f 100644 --- a/roles/kube-node/vars/main.yml +++ b/roles/kube-node/vars/main.yml @@ -12,5 +12,8 @@ KUBE_APISERVER: "{%- if inventory_hostname in groups['kube_master'] -%} \ {%- endif -%} \ {%- endif -%}" +# node local dns cache 离线镜像 +dnscache_offline: "k8s-dns-node-cache_{{ dnsNodeCacheVer }}.tar" + # 增加/删除 master 节点时,node 节点需要重新配置 haproxy MASTER_CHG: "no"