Skip to content

Commit

Permalink
更新增加master节点的步骤和文档
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgao1983 committed Mar 9, 2018
1 parent 4246064 commit e4685e5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
14 changes: 14 additions & 0 deletions 21.addmaster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 集群节点的公共配置任务
- hosts:
- kube-master
roles:
- prepare

# [可选]多master部署时的负载均衡配置
- hosts: lb
roles:
- lb

- hosts: kube-master
roles:
- kube-master
5 changes: 3 additions & 2 deletions 99.clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
- name: 清理证书目录和文件
file: name={{ item }} state=absent
with_items:
- "/etc/kubernetes/"
- "{{ ca_dir }}"
- /root/.kube
- /etc/docker
- "/root/.kube/"
- "/etc/docker/"
60 changes: 60 additions & 0 deletions docs/guide/op/AddMaster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## 增加 kube-master 节点

注意:目前仅支持按照本项目`多主模式`(hosts.m-masters.example)部署的`k8s`集群增加`master`节点

新增`kube-master`节点大致流程为:
- 节点预处理 prepare
- 重新配置LB节点的 haproxy服务
- 安装 master 节点服务

### 操作步骤

按照本项目说明,首先确保deploy节点能够ssh免密码登陆新增节点,然后在**deploy**节点执行三步:

- 修改ansible hosts 文件,在 [kube-master] 组添加新增的节点;在[lb] 组添加新增master 节点,举例如下:

``` bash
[kube-master]
192.168.1.1 NODE_IP="192.168.1.1"
192.168.1.2 NODE_IP="192.168.1.2"
192.168.1.5 NODE_IP="192.168.1.5" # 新增 master节点

[lb]
192.168.1.1 LB_IF="ens3" LB_ROLE=backup
192.168.1.4 LB_IF="ens3" LB_ROLE=master
[lb:vars]
master1="192.168.1.1:6443"
master2="192.168.1.2:6443"
master3="192.168.1.5:6443" # 新增 master节点
```
- 修改roles/lb/templates/haproxy.cfg.j2 文件,增加新增的master节点,举例如下:

``` bash
listen kube-master
bind 0.0.0.0:{{ MASTER_PORT }}
mode tcp
option tcplog
balance source
server s1 {{ master1 }} check inter 10000 fall 2 rise 2 weight 1
server s2 {{ master2 }} check inter 10000 fall 2 rise 2 weight 1
server s3 {{ master3 }} check inter 10000 fall 2 rise 2 weight 1
```

- 执行安装脚本

``` bash
$ cd /etc/ansible && ansible-playbook 20.addmaster.yml
```

### 验证

``` bash
# 在新节点master 服务状态
$ systemctl status kube-apiserver
$ systemctl status kube-controller-manager
$ systemctl status kube-scheduler

# 查看新master的服务日志
$ journalctl -u kube-apiserver -f

```
16 changes: 8 additions & 8 deletions docs/guide/op/AddNode.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## 增加 kube-node 节点

新增`kube-node`节点大致流程为:
- 1. 节点预处理 prepare
- 2. 安装 kubectl (可选)
- 3. 安装 docker
- 4. 安装 kubelet 和 kube-proxy
- 5. 准备网络插件 calico 或 flannel
- 6. 批准新节点 kubectl certificate approve
- 节点预处理 prepare
- 安装 kubectl (可选)
- 安装 docker
- 安装 kubelet 和 kube-proxy
- 准备网络插件 calico 或 flannel
- 批准新节点 kubectl certificate approve

### 操作步骤

按照本项目说明,首先确保deploy节点能够ssh免密码登陆新增节点,然后在**deploy**节点执行两步:

- 1. 修改ansible hosts 文件,在 [new-node] 组编辑需要新增的节点,例如:
- 修改ansible hosts 文件,在 [new-node] 组编辑需要新增的节点,例如:

``` bash
...
Expand All @@ -21,7 +21,7 @@
192.168.1.6 NODE_ID=node6 NODE_IP="192.168.1.6"
...
```
- 2. 执行安装脚本
- 执行安装脚本

``` bash
$ cd /etc/ansible && ansible-playbook 20.addnode.yml
Expand Down
10 changes: 10 additions & 0 deletions roles/kube-master/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
- kube-proxy
- kubelet

# 注册变量result,根据result结果判断是否已经生成过 kubernetes证书
# result|failed 说明没有生成过证书,下一步生成证书
# result|succeeded 说明已经有kubernetes证书,使用原证书,跳过生成证书步骤
- name: 注册变量result
command: ls /etc/kubernetes/ssl/kubernetes.pem
register: result
ignore_errors: True

- name: 创建 kubernetes 证书签名请求
template: src=kubernetes-csr.json.j2 dest={{ ca_dir }}/kubernetes-csr.json
when: result|failed

- name: 创建 kubernetes 证书和私钥
when: result|failed
shell: "cd {{ ca_dir }} && {{ bin_dir }}/cfssl gencert \
-ca={{ ca_dir }}/ca.pem \
-ca-key={{ ca_dir }}/ca-key.pem \
Expand Down

0 comments on commit e4685e5

Please sign in to comment.