kubeasz部署k8s

旧街凉风 提交于 2019-12-17 09:14:31

1部署

1.0)集群规划

hostnamectl set-hostname master01

hostnamectl set-hostname master02

hostnamectl set-hostname node01

hostnamectl set-hostname node02

 

vi /etc/hosts

192.168.198.154 master01

192.168.198.155 master02

192.168.198.156 node01

192.168.198.157 node02

scp /etc/hosts

scp /etc/hosts root@master02:/etc/hosts

scp /etc/hosts root@node01:/etc/hosts

scp /etc/hosts root@node02:/etc/hosts

 

ssh-keygen -t rsa

ssh-copy-id -i .ssh/id_rsa.pub root@master01

ssh-copy-id -i .ssh/id_rsa.pub root@master02

ssh-copy-id -i .ssh/id_rsa.pub root@node01

ssh-copy-id -i .ssh/id_rsa.pub root@node02

 

1.1)阿里云epel源

wget http://mirrors.aliyun.com/repo/epel-7.repo

mv epel-7.repo /etc/yum.repo.d/

1.2)安装python pip

yum install -y python-pip python3 python-netaddr

pip install pip --upgrade -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

pip install ansible==2.6.12 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

 

1.3到https://github.com/easzlab/kubeasz/releases

下载最新版

wget https://github.com/easzlab/kubeasz/archive/2.1.0.tar.gz

tar zvxf 2.1.0.tar.gz

cd kubeasz-2.1.0

1.4下载镜像

./tools/easzup -D

1.5配置example/hosts.multi-node

cp example/hosts.multi-node /etc/ansible/hosts

1.6安装

ansible-playbook -v 90.setup.yml

 

2删除node

easzctl del-node 192.168.198.157

3新增node

easzctl add-node 192.168.198.157

4新增 master

easzctl add-master 192.168.198.155

5删除master

easzctl del-master 192.168.198.155

6备份集群

ansible-playbook -v 23.backup.yml

7恢复集群

ansible-playbook -v 24.restore.yml

8停止集群

ansible-playbook -v 92.stop.yml

9启动集群

ansible-playbook -v 91.start.yml

10清除集群

ansible-playbook -v 99.clean.yml

11删除etcd节点---------------

easzctl del-etcd 192.168.198.156

12添加etcd节点

easzctl add-etcd 192.168.198.156

官方脚本有问题需要修改

a)/etc/ansible/tools/easzctl

ansible-playbook $BASEPATH/tools/01.addetcd.yml -e NODE_TO_ADD=$1 -e NEW_NODE_NAME=$NAME || { sed -i "/$1 NODE_NAME=$NAME/d" $BASEPATH/hosts; return 2; }

增加-e NEW_NODE_NAME=$NAME

b)01.addetcd.yml

# add new-etcd node, one at a time

- hosts: localhost

 

shell: "ETCDCTL_API=3 {{ bin_dir }}/etcdctl member add {{ NEW_NODE_NAME }} --peer-urls=https://{{ NODE_TO_ADD }}:2380"

 

13改变网络

编辑/etc/ansible/hosts网络变量

ansible-playbook -v tools/change_k8s_network.yml

 

14升级集群

快速k8s版本升级

快速升级是指只升级k8s版本,比较常见如Bug修复 重要特性发布时使用。

 

升级前对 etcd数据做备份,在任意 etcd节点上执行:

# snapshot备份

$ ETCDCTL_API=3 etcdctl snapshot save backup.db

# 查看备份

$ ETCDCTL_API=3 etcdctl --write-out=table snapshot status backup.db

 

首先去官网release下载待升级的k8s版本,例如https://dl.k8s.io/v1.17.0/kubernetes-server-linux-amd64.tar.gz

解压下载的tar.gz文件,找到如下kube*开头的二进制,复制替换ansible控制端目录/etc/ansible/bin对应文件

kube-apiserver

kube-controller-manager

kubectl

kubelet

kube-proxy

kube-scheduler

在ansible控制端执行ansible-playbook -t upgrade_k8s 22.upgrade.yml即可完成k8s 升级,不会中断业务应用

如果使用 easzctl 命令行,可按如下执行:

 

首先确认待升级的集群(如果有多集群的话) easzctl checkout <cluster_name>

执行升级 easzctl upgrade

 

 

升级 etcd: ansible-playbook -t upgrade_etcd 02.etcd.yml,注意:etcd 版本只能升级不能降低!

ansible-playbook -t upgrade_docker 03.docker.yml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!