- 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 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的部署文件 template: src=metrics-server/components.yaml.j2 dest={{ cluster_dir }}/yml/metrics-server.yaml run_once: true connection: local - name: 创建 metrics-server部署 shell: "{{ base_dir }}/bin/kubectl apply -f {{ cluster_dir }}/yml/metrics-server.yaml" run_once: true connection: local