2018-05-19 22:40:41 +08:00
|
|
|
|
# [可选]操作系统安全加固 https://github.com/dev-sec/ansible-os-hardening
|
|
|
|
|
- hosts: all
|
|
|
|
|
roles:
|
|
|
|
|
- { role: os-harden, when: "OS_HARDEN is defined and OS_HARDEN == 'yes'" }
|
|
|
|
|
|
2017-11-12 14:54:20 +08:00
|
|
|
|
# 在deploy节点生成CA相关证书,以供整个集群使用
|
2018-01-02 22:12:51 +08:00
|
|
|
|
# 以及初始化kubedns.yaml配置文件
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- hosts: deploy
|
2017-11-11 19:14:21 +08:00
|
|
|
|
roles:
|
2017-12-08 17:43:51 +08:00
|
|
|
|
- deploy
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2017-11-12 14:54:20 +08:00
|
|
|
|
# 集群节点的公共配置任务
|
2017-11-21 11:27:06 +08:00
|
|
|
|
- hosts:
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- kube-master
|
|
|
|
|
- kube-node
|
2017-11-28 21:35:40 +08:00
|
|
|
|
- deploy
|
2017-11-21 11:27:06 +08:00
|
|
|
|
- etcd
|
2018-01-02 22:12:51 +08:00
|
|
|
|
- lb
|
2017-11-11 19:14:21 +08:00
|
|
|
|
roles:
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- prepare
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2017-11-21 11:27:06 +08:00
|
|
|
|
# [可选]多master部署时的负载均衡配置
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- hosts: lb
|
2017-11-11 19:14:21 +08:00
|
|
|
|
roles:
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- lb
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2018-01-02 22:12:51 +08:00
|
|
|
|
# 创建etcd集群
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- hosts: etcd
|
2017-11-11 19:14:21 +08:00
|
|
|
|
roles:
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- etcd
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2018-01-02 22:12:51 +08:00
|
|
|
|
# docker服务安装
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- hosts:
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- kube-master
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- kube-node
|
2017-11-21 11:27:06 +08:00
|
|
|
|
roles:
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- docker
|
2017-11-21 11:27:06 +08:00
|
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- hosts: kube-master
|
|
|
|
|
roles:
|
|
|
|
|
- kube-master
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- kube-node
|
|
|
|
|
# 禁止业务 pod调度到 master节点
|
|
|
|
|
tasks:
|
|
|
|
|
- name: 禁止业务 pod调度到 master节点
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl cordon {{ NODE_IP }} "
|
|
|
|
|
when: DEPLOY_MODE != "allinone"
|
|
|
|
|
ignore_errors: true
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2018-05-23 09:45:06 +08:00
|
|
|
|
- name: 设置master节点role
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl label node {{ NODE_IP }} kubernetes.io/role=master --overwrite"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2018-01-02 22:12:51 +08:00
|
|
|
|
# node 节点部署
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- hosts: kube-node
|
|
|
|
|
roles:
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- { role: kube-node, when: "DEPLOY_MODE != 'allinone'" }
|
2018-01-02 22:12:51 +08:00
|
|
|
|
|
2018-01-05 23:05:22 +08:00
|
|
|
|
# 集群网络插件部署,只能选择一种安装
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- hosts:
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- kube-master
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- kube-node
|
2018-01-02 22:12:51 +08:00
|
|
|
|
roles:
|
|
|
|
|
- { role: calico, when: "CLUSTER_NETWORK == 'calico'" }
|
|
|
|
|
- { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" }
|