2019-05-29 20:45:25 +08:00
|
|
|
|
- name: 在 node 节点创建相关目录
|
|
|
|
|
file: path={{ item }} state=directory
|
|
|
|
|
with_items:
|
|
|
|
|
- /opt/kube/kube-system
|
|
|
|
|
|
2019-05-29 22:49:04 +08:00
|
|
|
|
# 设置 dns svc ip (这里选用 SERVICE_CIDR 中第2个IP)
|
|
|
|
|
- name: 注册变量 DNS_SVC_IP
|
|
|
|
|
shell: echo {{ SERVICE_CIDR }}|cut -d/ -f1|awk -F. '{print $1"."$2"."$3"."$4+2}'
|
|
|
|
|
register: DNS_SVC_IP
|
|
|
|
|
|
|
|
|
|
- name: 设置变量 CLUSTER_DNS_SVC_IP
|
|
|
|
|
set_fact: CLUSTER_DNS_SVC_IP={{ DNS_SVC_IP.stdout }}
|
|
|
|
|
|
2019-05-29 20:45:25 +08:00
|
|
|
|
# DNS文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
|
|
|
|
|
- name: 准备 DNS的部署文件
|
|
|
|
|
template: src={{ item }}.yaml.j2 dest=/opt/kube/kube-system/{{ item }}.yaml
|
|
|
|
|
with_items:
|
|
|
|
|
- kubedns
|
|
|
|
|
- coredns
|
|
|
|
|
|
|
|
|
|
- name: 获取所有已经创建的POD信息
|
|
|
|
|
command: "{{ bin_dir }}/kubectl get pod --all-namespaces"
|
|
|
|
|
register: pod_info
|
2018-08-31 22:58:44 +08:00
|
|
|
|
run_once: true
|
|
|
|
|
|
2018-10-14 10:17:20 +08:00
|
|
|
|
- name: 获取已下载离线镜像信息
|
|
|
|
|
command: "ls {{ base_dir }}/down"
|
|
|
|
|
register: download_info
|
|
|
|
|
connection: local
|
|
|
|
|
run_once: true
|
|
|
|
|
|
2018-06-28 10:52:20 +08:00
|
|
|
|
- block:
|
2019-05-18 18:07:34 +08:00
|
|
|
|
- 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 }}"
|
2019-05-21 23:47:49 +08:00
|
|
|
|
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"'
|
2018-08-12 19:27:16 +08:00
|
|
|
|
|
2018-06-28 10:52:20 +08:00
|
|
|
|
- name: 创建{{ dns_backend }}部署
|
2019-05-29 20:45:25 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ dns_backend }}.yaml"
|
2018-08-12 19:27:16 +08:00
|
|
|
|
run_once: true
|
|
|
|
|
when:
|
|
|
|
|
- '"kube-dns" not in pod_info.stdout'
|
|
|
|
|
- '"coredns" not in pod_info.stdout'
|
|
|
|
|
- 'dns_install == "yes"'
|
2018-06-19 21:45:17 +08:00
|
|
|
|
ignore_errors: true
|
2018-06-17 23:19:04 +08:00
|
|
|
|
|
2018-06-28 10:52:20 +08:00
|
|
|
|
- block:
|
2019-05-18 18:07:34 +08:00
|
|
|
|
- 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 }}"
|
2019-05-21 23:47:49 +08:00
|
|
|
|
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"'
|
2018-08-12 19:27:16 +08:00
|
|
|
|
|
2018-06-28 10:52:20 +08:00
|
|
|
|
- name: 创建 metrics-server部署
|
2019-05-29 20:45:25 +08:00
|
|
|
|
shell: "{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/manifests/metrics-server"
|
2018-08-12 19:27:16 +08:00
|
|
|
|
run_once: true
|
2019-05-29 20:45:25 +08:00
|
|
|
|
connection: local
|
2018-06-17 23:19:04 +08:00
|
|
|
|
when: '"metrics-server" not in pod_info.stdout and metricsserver_install == "yes"'
|
2018-06-19 21:45:17 +08:00
|
|
|
|
ignore_errors: true
|
2018-06-17 23:19:04 +08:00
|
|
|
|
|
2019-03-22 16:11:41 +08:00
|
|
|
|
# 现阶段 dashboard 获取metrics仍旧依赖于heapster,因此需连带安装heapster
|
2018-06-28 10:52:20 +08:00
|
|
|
|
- block:
|
2019-05-18 18:07:34 +08:00
|
|
|
|
- block:
|
2019-06-13 17:16:52 +08:00
|
|
|
|
- name: 尝试推送离线 dashboard heapster镜像(若执行失败,可忽略)
|
|
|
|
|
copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }}
|
|
|
|
|
when: 'item in download_info.stdout'
|
|
|
|
|
with_items:
|
|
|
|
|
- "{{ dashboard_offline }}"
|
|
|
|
|
- "{{ heapster_offline }}"
|
|
|
|
|
|
2019-05-18 18:07:34 +08:00
|
|
|
|
- name: 获取dashboard离线镜像推送情况
|
|
|
|
|
command: "ls /opt/kube/images"
|
|
|
|
|
register: image_info
|
|
|
|
|
|
2019-06-13 17:16:52 +08:00
|
|
|
|
- name: 导入 dashboard heapster的离线镜像(docker)
|
|
|
|
|
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}"
|
|
|
|
|
with_items:
|
|
|
|
|
- "{{ dashboard_offline }}"
|
|
|
|
|
- "{{ heapster_offline }}"
|
|
|
|
|
when: "item in image_info.stdout and CONTAINER_RUNTIME == 'docker'"
|
|
|
|
|
|
|
|
|
|
- name: 导入 dashboard heapster的离线镜像(containerd)
|
|
|
|
|
shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ item }}"
|
|
|
|
|
with_items:
|
|
|
|
|
- "{{ dashboard_offline }}"
|
|
|
|
|
- "{{ heapster_offline }}"
|
|
|
|
|
when: "item in image_info.stdout and CONTAINER_RUNTIME == 'containerd'"
|
|
|
|
|
|
2018-06-28 10:52:20 +08:00
|
|
|
|
- name: 创建 dashboard部署
|
2019-05-29 20:45:25 +08:00
|
|
|
|
shell: "{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/manifests/dashboard && \
|
|
|
|
|
{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/manifests/heapster/heapster-only"
|
2018-08-12 19:27:16 +08:00
|
|
|
|
run_once: true
|
2019-05-29 20:45:25 +08:00
|
|
|
|
connection: local
|
2018-06-17 23:19:04 +08:00
|
|
|
|
when: '"kubernetes-dashboard" not in pod_info.stdout and dashboard_install == "yes"'
|
2018-06-19 21:45:17 +08:00
|
|
|
|
ignore_errors: true
|
2018-06-17 23:19:04 +08:00
|
|
|
|
|
2018-12-21 22:35:15 +08:00
|
|
|
|
- import_tasks: ingress.yml
|
|
|
|
|
when: '"ingress-controller" not in pod_info.stdout and ingress_install == "yes"'
|
2018-06-23 12:42:02 +08:00
|
|
|
|
|
2018-10-28 21:20:26 +08:00
|
|
|
|
- block:
|
2019-05-18 18:07:34 +08:00
|
|
|
|
- block:
|
|
|
|
|
- name: 尝试推送离线 metallb镜像(若执行失败,可忽略)
|
|
|
|
|
copy: src={{ base_dir }}/down/{{ metallb_offline }} dest=/opt/kube/images/{{ metallb_offline }}
|
|
|
|
|
when: 'metallb_offline in download_info.stdout'
|
|
|
|
|
|
|
|
|
|
- name: 获取metallb离线镜像推送情况
|
|
|
|
|
command: "ls /opt/kube/images"
|
|
|
|
|
register: image_info
|
|
|
|
|
|
|
|
|
|
- name: 导入 metallb的离线镜像(若执行失败,可忽略)
|
|
|
|
|
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metallb_offline }}"
|
2019-05-21 23:47:49 +08:00
|
|
|
|
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"'
|
2018-10-28 21:20:26 +08:00
|
|
|
|
|
|
|
|
|
- name: 生成 metallb 相关 manifests
|
|
|
|
|
template: src=metallb/{{ item }}.j2 dest=/opt/kube/kube-system/{{ item }}
|
|
|
|
|
with_items:
|
|
|
|
|
- "metallb.yaml"
|
|
|
|
|
- "{{ metallb_protocol }}.yaml"
|
|
|
|
|
|
|
|
|
|
- name: 创建 metallb controller 部署
|
2019-05-29 20:45:25 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/metallb.yaml && \
|
|
|
|
|
{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ metallb_protocol }}.yaml"
|
2018-10-28 21:20:26 +08:00
|
|
|
|
run_once: true
|
|
|
|
|
when: '"metallb" not in pod_info.stdout and metallb_install == "yes"'
|
|
|
|
|
ignore_errors: true
|