From 61d8f032c12584e8bd85c7b294554536a5b65a01 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Thu, 6 Dec 2018 10:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8D=87=E7=BA=A7=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E7=9B=B8=E5=85=B3=E8=84=9A=E6=9C=AC=E5=92=8C=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.docker.yml | 2 ++ 22.upgrade.yml | 16 ++------------- docs/op/upgrade.md | 39 ++++++++++++++++++++++++------------ roles/etcd/tasks/main.yml | 5 +++-- roles/prepare/tasks/main.yml | 6 ++++-- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/03.docker.yml b/03.docker.yml index 02f3a7e..b0711f5 100644 --- a/03.docker.yml +++ b/03.docker.yml @@ -1,6 +1,8 @@ # to install docker service - hosts: - kube-master + - new-master - kube-node + - new-node roles: - docker diff --git a/22.upgrade.yml b/22.upgrade.yml index e278668..529b9eb 100644 --- a/22.upgrade.yml +++ b/22.upgrade.yml @@ -2,26 +2,14 @@ # Read the guide: 'op/upgrade.md' . # update kubectl binary -- hosts: - - kube-master - - kube-node - - deploy - roles: - - prepare - -# update etcd -- hosts: etcd - roles: - - etcd - -# update docker binary - hosts: - kube-master - new-master - kube-node - new-node + - deploy roles: - - docker + - prepare # update masters - hosts: diff --git a/docs/op/upgrade.md b/docs/op/upgrade.md index c711db8..7b07ab9 100644 --- a/docs/op/upgrade.md +++ b/docs/op/upgrade.md @@ -1,13 +1,13 @@ -## 升级注意事项 +## k8s 集群升级 -集群更新存在一定风险,请谨慎操作。 +集群升级存在一定风险,请谨慎操作。 - 项目分支`master`安装的集群可以在k8s 1.8/1.9/1.10/1.11/1.12 任意小版本、大版本间升级(特别注意如果跨大版本升级需要修改/etc/ansible/hosts文件中的参数K8S_VER) - 项目分支`closed`(已停止更新)安装的集群目前只能进行小版本1.8.x的升级 ### 备份etcd数据 -- 升级前手动对 etcd数据做镜像备份,在任意 etcd节点上执行: +- 升级前对 etcd数据做备份,在任意 etcd节点上执行: ``` bash # snapshot备份 @@ -17,18 +17,31 @@ $ ETCDCTL_API=3 etcdctl --write-out=table snapshot status backup.db ``` - `kubeasz`项目也可以方便执行 `ansible-playbook /etc/ansible/23.backup.yml`,详情阅读文档[备份恢复](cluster_restore.md) -### 升级步骤 +### 快速k8s版本升级 -- 1.下载新的二进制解压并替换 `/etc/ansible/bin/` 目录下文件 +快速升级是指只升级`k8s`版本,比较常见如`Bug修复` `重要特性发布`时使用。 -- 2a.如果不需要升级 docker版本:执行 `ansible-playbook -t upgrade_k8s 22.upgrade.yml` 即可完成k8s 升级,不会中断业务应用 - - 注:建议使用稳定版本 docker +- 首先去官网release下载待升级的k8s版本,例如`https://dl.k8s.io/v1.11.5/kubernetes-server-linux-amd64.tar.gz` +- 解压下载的tar.gz文件,找到如下`kube*`开头的二进制,复制替换deploy节点目录`/etc/ansible/bin`对应文件 + - kube-apiserver + - kube-controller-manager + - kubectl + - kubelet + - kube-proxy + - kube-scheduler +- 在deploy节点执行`ansible-playbook -t upgrade_k8s 22.upgrade.yml`即可完成k8s 升级,不会中断业务应用 -- 2b.如果可以接受短暂业务中断,执行 `ansible-playbook -t upgrade_k8s,upgrade_docker 22.upgrade.yml` 即可升级 k8s和 docker(如果有新的docker二进制) +### 其他升级说明 -- 2c.如果要求零中断升级 k8s和 docker - - i 执行 `ansible-playbook -t upgrade_k8s,download_docker 22.upgrade.yml` (该步骤不会影响k8s上的业务应用) - - ii 逐个升级重启每个node节点的dockerd服务 - - 待重启节点,先应用`kubectl cordon`和`kubectl drain`命令迁移业务pod - - 待重启节点执行 `systemctl restart docker` +其他升级是指升级k8s组件包括:`etcd版本` `docker版本`,一般不需要用到,以下仅作说明。 + +- 1.下载所有组件相关新的二进制解压并替换 `/etc/ansible/bin/` 目录下文件 + +- 2.升级 etcd: `ansible-playbook -t upgrade_etcd 02.etcd.yml` + +- 3.升级 docker (建议使用k8s官方支持的docker稳定版本) + - 如果可以接受短暂业务中断,执行 `ansible-playbook -t upgrade_docker 03.docker.yml` + - 如果要求零中断升级,执行 `ansible-playbook -t download_docker 03.docker.yml`,然后手动执行如下 + - 待升级节点,先应用`kubectl cordon`和`kubectl drain`命令迁移业务pod + - 待升级节点执行 `systemctl restart docker` - 恢复节点可调度 `kubectl uncordon` diff --git a/roles/etcd/tasks/main.yml b/roles/etcd/tasks/main.yml index 89a1e59..cb43e06 100644 --- a/roles/etcd/tasks/main.yml +++ b/roles/etcd/tasks/main.yml @@ -3,7 +3,7 @@ with_items: - etcd - etcdctl - tags: upgrade_k8s + tags: upgrade_etcd - name: 创建etcd证书目录 file: name=/etc/etcd/ssl state=directory @@ -31,6 +31,7 @@ - name: 创建etcd的systemd unit文件 template: src=etcd.service.j2 dest=/etc/systemd/system/etcd.service + tags: upgrade_etcd - name: 开机启用etcd服务 shell: systemctl enable etcd @@ -38,4 +39,4 @@ - name: 开启etcd服务 shell: systemctl daemon-reload && systemctl restart etcd - tags: upgrade_k8s + tags: upgrade_etcd diff --git a/roles/prepare/tasks/main.yml b/roles/prepare/tasks/main.yml index fe7a3fa..3ba255f 100644 --- a/roles/prepare/tasks/main.yml +++ b/roles/prepare/tasks/main.yml @@ -12,13 +12,15 @@ - "{{ ca_dir }}" - /root/.kube -- name: 下载证书工具 CFSSL和 kubectl +- name: 分发证书工具 CFSSL copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755 with_items: - cfssl - cfssl-certinfo - cfssljson - - kubectl + +- name: 分发 kubectl + copy: src={{ base_dir }}/bin/kubectl dest={{ bin_dir }}/kubectl mode=0755 tags: upgrade_k8s - name: 分发 kubeconfig配置文件