2017-11-27 20:22:53 +08:00
|
|
|
|
## 00-集群规划和基础参数设定.md
|
2017-11-30 15:01:24 +08:00
|
|
|
|
|
|
|
|
|
多节点高可用集群部署步骤与[AllinOne部署](quickStart.md)基本一致,增加LB 负载均衡部署步骤。
|
|
|
|
|
|
2017-12-06 21:08:27 +08:00
|
|
|
|
## 高可用集群所需节点配置如下:
|
2018-03-17 17:00:42 +08:00
|
|
|
|
+ 部署节点------x1 : 运行这份 ansible 脚本的节点
|
|
|
|
|
+ etcd节点------x3 : 注意etcd集群必须是1,3,5,7...奇数个节点
|
|
|
|
|
+ master节点----x2 : 根据实际集群规模可以增加节点数,需要额外规划一个master VIP(虚地址)
|
|
|
|
|
+ lb节点--------x2 : 负载均衡节点两个,安装 haproxy+keepalived
|
|
|
|
|
+ node节点------x3 : 真正应用负载的节点,根据需要增加机器配置和节点数
|
2017-11-30 15:01:24 +08:00
|
|
|
|
|
2018-06-19 21:45:17 +08:00
|
|
|
|
**请注意对于多节点集群,请确保各节点时区设置一致,并使用ntp服务器同步各节点时间。**
|
2018-03-02 15:16:40 +08:00
|
|
|
|
|
2018-03-17 17:00:42 +08:00
|
|
|
|
生产环境使用建议一个节点只是一个角色,这里演示环境将节点绑定多个角色。项目预定义了3个例子,请修改后完成适合你的集群规划。
|
2017-12-06 21:08:27 +08:00
|
|
|
|
|
2018-01-05 23:05:22 +08:00
|
|
|
|
+ [单节点](../example/hosts.allinone.example)
|
2017-12-06 21:08:27 +08:00
|
|
|
|
+ [单主多节点](../example/hosts.s-master.example)
|
|
|
|
|
+ [多主多节点](../example/hosts.m-masters.example)
|
2017-11-30 15:01:24 +08:00
|
|
|
|
|
|
|
|
|
## 部署步骤
|
|
|
|
|
|
2018-03-17 17:00:42 +08:00
|
|
|
|
按照[多主多节点](../example/hosts.m-masters.example)示例的节点配置,准备4台虚机,测试搭建一个多主高可用集群。
|
2017-12-18 22:56:59 +08:00
|
|
|
|
|
|
|
|
|
### 1.基础系统配置
|
|
|
|
|
|
2018-06-23 12:42:02 +08:00
|
|
|
|
+ 推荐内存2G/硬盘30G以上
|
2017-12-18 22:56:59 +08:00
|
|
|
|
+ 最小化安装`Ubuntu 16.04 server`或者`CentOS 7 Minimal`
|
|
|
|
|
+ 配置基础网络、更新源、SSH登陆等
|
|
|
|
|
|
2017-12-21 19:24:39 +08:00
|
|
|
|
### 2.在每个节点安装依赖工具
|
2017-12-18 22:56:59 +08:00
|
|
|
|
|
|
|
|
|
Ubuntu 16.04 请执行以下脚本:
|
|
|
|
|
|
2017-11-30 15:01:24 +08:00
|
|
|
|
``` bash
|
|
|
|
|
# 文档中脚本默认均以root用户执行
|
|
|
|
|
apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
|
2017-12-18 22:56:59 +08:00
|
|
|
|
# 安装python2
|
2017-11-30 15:01:24 +08:00
|
|
|
|
apt-get install python2.7
|
|
|
|
|
# Ubuntu16.04可能需要配置以下软连接
|
|
|
|
|
ln -s /usr/bin/python2.7 /usr/bin/python
|
|
|
|
|
```
|
2017-12-18 22:56:59 +08:00
|
|
|
|
CentOS 7 请执行以下脚本:
|
|
|
|
|
|
2017-11-30 15:01:24 +08:00
|
|
|
|
``` bash
|
2017-12-18 22:56:59 +08:00
|
|
|
|
# 文档中脚本默认均以root用户执行
|
|
|
|
|
# 安装 epel 源并更新
|
|
|
|
|
yum install epel-release -y
|
|
|
|
|
yum update
|
|
|
|
|
# 安装python
|
|
|
|
|
yum install python -y
|
|
|
|
|
```
|
2017-12-21 19:24:39 +08:00
|
|
|
|
### 3.在deploy节点安装及准备ansible
|
2017-12-18 22:56:59 +08:00
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
# Ubuntu 16.04
|
|
|
|
|
apt-get install git python-pip -y
|
|
|
|
|
# CentOS 7
|
|
|
|
|
yum install git python-pip -y
|
|
|
|
|
# pip安装ansible(国内如果安装太慢可以直接用pip阿里云加速)
|
2017-11-30 15:01:24 +08:00
|
|
|
|
#pip install pip --upgrade
|
|
|
|
|
#pip install ansible
|
|
|
|
|
pip install pip --upgrade -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
|
|
|
pip install --no-cache-dir ansible -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
|
|
|
```
|
2018-06-14 00:20:16 +08:00
|
|
|
|
|
|
|
|
|
在`Ubuntu 16.04`中,如果出现以下错误:
|
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
|
File "/usr/bin/pip", line 9, in <module>
|
|
|
|
|
from pip import main
|
|
|
|
|
ImportError: cannot import name main
|
|
|
|
|
```
|
|
|
|
|
将`/usr/bin/pip`做以下修改:
|
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
#原代码
|
|
|
|
|
from pip import main
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
#修改后
|
|
|
|
|
from pip import __main__
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
sys.exit(__main__._main())
|
|
|
|
|
```
|
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
- 在deploy节点配置免密码登陆
|
2017-12-18 22:56:59 +08:00
|
|
|
|
|
2017-11-30 15:01:24 +08:00
|
|
|
|
``` bash
|
|
|
|
|
ssh-keygen -t rsa -b 2048 回车 回车 回车
|
2017-12-21 19:24:39 +08:00
|
|
|
|
ssh-copy-id $IPs #$IPs为所有节点地址包括自身,按照提示输入yes 和root密码
|
2017-12-06 21:56:12 +08:00
|
|
|
|
```
|
2018-06-29 18:14:59 +08:00
|
|
|
|
### 4.在deploy节点编排k8s安装
|
2017-12-21 16:24:41 +08:00
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
- 4.1 下载项目源码
|
2017-12-21 16:24:41 +08:00
|
|
|
|
``` bash
|
2018-06-29 18:14:59 +08:00
|
|
|
|
# 方式一:使用git clone
|
2017-12-21 16:24:41 +08:00
|
|
|
|
git clone https://github.com/gjmzj/kubeasz.git
|
2018-03-20 15:52:13 +08:00
|
|
|
|
mkdir -p /etc/ansible
|
|
|
|
|
mv kubeasz/* /etc/ansible
|
2018-06-29 18:14:59 +08:00
|
|
|
|
# 方式二:从发布页面 https://github.com/gjmzj/kubeasz/releases 下载源码解压到同样目录
|
|
|
|
|
```
|
|
|
|
|
- 4.2a 下载二进制文件
|
|
|
|
|
请从分享的百度云链接下载 https://pan.baidu.com/s/1c4RFaA,解压到/etc/ansible/bin目录,如果你有合适网络环境也可以按照/down/download.sh自行从官网下载各种tar包
|
|
|
|
|
``` bash
|
|
|
|
|
tar zxvf k8s.1-9-8.tar.gz # 以安装k8s v1.9.8为例
|
2017-12-21 16:24:41 +08:00
|
|
|
|
mv bin/* /etc/ansible/bin
|
|
|
|
|
```
|
2018-06-29 18:14:59 +08:00
|
|
|
|
- 4.2b [可选]下载离线docker镜像
|
|
|
|
|
服务器使用内部yum源/apt源,但是无法访问公网情况下,请下载离线docker镜像完成集群安装;从百度云盘把`basic_images_kubeasz_x.y.tar.gz` 下载解压到`/etc/ansible/down` 目录
|
2017-12-06 21:56:12 +08:00
|
|
|
|
``` bash
|
2018-06-29 18:14:59 +08:00
|
|
|
|
tar zxvf basic_images_kubeasz_0.2.tar.gz -C /etc/ansible/down
|
2017-12-06 21:56:12 +08:00
|
|
|
|
```
|
2018-06-29 18:14:59 +08:00
|
|
|
|
- 4.3 配置集群参数
|
|
|
|
|
``` bash
|
|
|
|
|
cd /etc/ansible
|
|
|
|
|
cp example/hosts.m-masters.example hosts
|
|
|
|
|
vim hosts # 根据实际情况修改此hosts文件
|
|
|
|
|
# 验证ansible安装,正常能看到每个节点返回 SUCCESS
|
|
|
|
|
ansible all -m ping
|
2017-11-30 15:01:24 +08:00
|
|
|
|
```
|
2018-06-29 18:14:59 +08:00
|
|
|
|
- 4.4 开始安装
|
|
|
|
|
如果你对集群安装流程不熟悉,请阅读项目首页 **安装步骤** 讲解后分步安装,并对 **每步都进行验证**
|
2017-11-30 15:01:24 +08:00
|
|
|
|
``` bash
|
2018-03-17 17:00:42 +08:00
|
|
|
|
# 分步安装
|
|
|
|
|
ansible-playbook 01.prepare.yml
|
|
|
|
|
ansible-playbook 02.etcd.yml
|
|
|
|
|
ansible-playbook 03.docker.yml
|
|
|
|
|
ansible-playbook 04.kube-master.yml
|
|
|
|
|
ansible-playbook 05.kube-node.yml
|
|
|
|
|
ansible-playbook 06.network.yml
|
2018-06-19 21:45:17 +08:00
|
|
|
|
ansible-playbook 07.cluster-addon.yml
|
2018-03-17 17:00:42 +08:00
|
|
|
|
# 一步安装
|
2018-06-29 18:14:59 +08:00
|
|
|
|
#ansible-playbook 90.setup.yml
|
2017-11-30 15:01:24 +08:00
|
|
|
|
```
|
2017-11-30 18:25:47 +08:00
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
+ [可选]对集群所有节点进行操作系统层面的安全加固 `ansible-playbook roles/os-harden/os-harden.yml`,详情请参考[os-harden项目](https://github.com/dev-sec/ansible-os-hardening)
|
|
|
|
|
|
|
|
|
|
|
2017-12-18 22:56:59 +08:00
|
|
|
|
[前一篇](quickStart.md) -- [后一篇](01-创建CA证书和环境配置.md)
|