kubeasz/roles/kube-node/tasks/node_lb.yml

74 lines
2.2 KiB
YAML
Raw Normal View History

2019-05-30 21:37:01 +08:00
# kube-node 节点成员不能同时是 ex-lb 节点,因为它们都需要安装 haproxy
- name: fail info1
fail: msg="an 'kube-node' node CAN NOT be a 'ex-lb' node at the same time"
when: "inventory_hostname in groups['ex-lb']"
2019-06-01 09:24:43 +08:00
tags: restart_lb
2019-05-30 21:37:01 +08:00
2019-05-28 23:46:22 +08:00
- name: 安装 haproxy
package: name=haproxy state=present
2019-06-28 19:36:53 +08:00
when: 'INSTALL_SOURCE != "offline"'
# 离线安装 haproxy
- import_tasks: offline.yml
when: 'INSTALL_SOURCE == "offline"'
2019-05-28 23:46:22 +08:00
- name: 创建haproxy配置目录
file: name=/etc/haproxy state=directory
- name: 修改centos的haproxy.service
template: src=haproxy.service.j2 dest=/usr/lib/systemd/system/haproxy.service
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
tags: restart_lb
- name: 配置 haproxy
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
tags: restart_lb
- name: daemon-reload for haproxy.service
shell: systemctl daemon-reload
tags: restart_lb
- name: 开机启用haproxy服务
shell: systemctl enable haproxy
ignore_errors: true
- name: 停止haproxy服务
shell: systemctl stop haproxy
tags: restart_lb
2019-06-09 10:58:01 +08:00
# 仅 master 节点数大于1时才启动haproxy
- name: 开启haproxy服务
shell: systemctl start haproxy
when: "groups['kube-master']|length > 1"
2019-05-28 23:46:22 +08:00
tags: restart_lb
2019-06-04 13:06:11 +08:00
# master 节点从1个增加到2个时候需要修改如下配置
# master 节点从2个减少到1个时候也需要修改
- block:
- name: 替换 kubeconfig 的 apiserver 地址
lineinfile:
dest: /root/.kube/config
regexp: "^ server"
line: " server: {{ KUBE_APISERVER }}"
- name: 替换 kubelet.kubeconfig 的 apiserver 地址
lineinfile:
dest: /etc/kubernetes/kubelet.kubeconfig
regexp: "^ server"
line: " server: {{ KUBE_APISERVER }}"
- name: 替换 kube-proxy.kubeconfig 的 apiserver 地址
lineinfile:
dest: /etc/kubernetes/kube-proxy.kubeconfig
regexp: "^ server"
line: " server: {{ KUBE_APISERVER }}"
- name: restart kube-node service
service: name={{ item }} state=restarted
with_items:
- kubelet
- kube-proxy
ignore_errors: true
when: "MASTER_CHG == 'yes' and groups['kube-master']|length < 3"
tags: restart_lb