forked from easzlab/kubeasz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
144 lines (119 loc) · 6.27 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
- name: 在 node 节点创建相关目录
file: path={{ item }} state=directory
with_items:
- /opt/kube/kube-system
# 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
run_once: true
- name: 获取已下载离线镜像信息
command: "ls {{ base_dir }}/down"
register: download_info
connection: local
run_once: true
- block:
- 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 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 }}.yaml"
run_once: true
when:
- '"kube-dns" not in pod_info.stdout'
- '"coredns" not in pod_info.stdout'
- 'dns_install == "yes"'
ignore_errors: true
- block:
- 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 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: "{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/manifests/metrics-server"
run_once: true
connection: local
when: '"metrics-server" not in pod_info.stdout and metricsserver_install == "yes"'
ignore_errors: true
# 现阶段 dashboard 获取metrics仍旧依赖于heapster,因此需连带安装heapster
- block:
- block:
- 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 }}"
- name: 获取dashboard离线镜像推送情况
command: "ls /opt/kube/images"
register: image_info
- 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'"
- name: 创建 dashboard部署
shell: "{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/manifests/dashboard && \
{{ base_dir }}/bin/kubectl apply -f {{ base_dir }}/manifests/heapster/heapster-only"
run_once: true
connection: local
when: '"kubernetes-dashboard" not in pod_info.stdout and dashboard_install == "yes"'
ignore_errors: true
- import_tasks: ingress.yml
when: '"ingress-controller" not in pod_info.stdout and ingress_install == "yes"'
- block:
- 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 }}"
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 }}
with_items:
- "metallb.yaml"
- "{{ metallb_protocol }}.yaml"
- name: 创建 metallb controller 部署
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/metallb.yaml && \
{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/{{ metallb_protocol }}.yaml"
run_once: true
when: '"metallb" not in pod_info.stdout and metallb_install == "yes"'
ignore_errors: true