kubeasz/roles/cluster-addon/tasks/main.yml

127 lines
5.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

- name: 创建相关目录
file: path={{ item }} state=directory
with_items:
- /opt/kube/kube-system/kubedns
- /opt/kube/kube-system/coredns
# DNS文件中部分参数根据hosts文件设置而定因此需要用template模块替换参数
- name: 准备 DNS的部署文件
template: src={{ item }}.yaml.j2 dest=/opt/kube/kube-system/{{ item }}/{{ item }}.yaml
with_items:
- kubedns
- coredns
- name: 获取所有已经创建的POD信息
command: "{{ bin_dir }}/kubectl get pod -n kube-system"
register: pod_info
run_once: true
- name: 获取已下载离线镜像信息
command: "ls {{ base_dir }}/down"
register: download_info
delegate_to: "{{ groups.deploy[0] }}"
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'
- name: 创建{{ dns_backend }}部署
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ dns_backend }}"
run_once: true
when:
- '"kube-dns" not in pod_info.stdout'
- '"coredns" not in pod_info.stdout'
- 'dns_install == "yes"'
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'
- name: 创建 metrics-server部署
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/metrics-server"
delegate_to: "{{ groups.deploy[0] }}"
run_once: true
when: '"metrics-server" not in pod_info.stdout and metricsserver_install == "yes"'
ignore_errors: true
- 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'
- name: 创建 dashboard部署
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/dashboard"
delegate_to: "{{ groups.deploy[0] }}"
run_once: true
when: '"kubernetes-dashboard" not in pod_info.stdout and dashboard_install == "yes"'
ignore_errors: true
- 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'
- name: 创建 traefik部署
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/ingress/traefik-ingress.yaml"
delegate_to: "{{ groups.deploy[0] }}"
run_once: true
when: '"traefik-ingress-controller" not in pod_info.stdout and ingress_install == "yes"'
ignore_errors: true
- 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'
- name: 创建 heapster部署
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/heapster/heapster.yaml"
delegate_to: "{{ groups.deploy[0] }}"
run_once: true
when: '"heapster" not in pod_info.stdout and heapster_install == "yes"'
ignore_errors: true