【k8s】使用kubeasz一键安装k8s多主集群
1、 kubeasz
https://github.com/easzlab/kubeasz
2、文档
https://github.com/easzlab/kubeasz/tree/master/docs
3、quickstart
https://github.com/easzlab/kubeasz/blob/master/docs/setup/quickStart.md
4、ezctl介绍
https://github.com/easzlab/kubeasz/blob/master/docs/setup/ezctl.md
Usage: ezctl COMMAND [args] ------------------------------------------------------------------------------------- Cluster setups: list to list all of the managed clusters checkout <cluster> to switch default kubeconfig of the cluster new <cluster> to start a new k8s deploy with name 'cluster' setup <cluster> <step> to setup a cluster, also supporting a step-by-step way start <cluster> to start all of the k8s services stopped by 'ezctl stop' stop <cluster> to stop all of the k8s services temporarily upgrade <cluster> to upgrade the k8s cluster destroy <cluster> to destroy the k8s cluster backup <cluster> to backup the cluster state (etcd snapshot) restore <cluster> to restore the cluster state from backups start-aio to quickly setup an all-in-one cluster with 'default' settings Cluster ops: add-etcd <cluster> <ip> to add a etcd-node to the etcd cluster add-master <cluster> <ip> to add a master node to the k8s cluster add-node <cluster> <ip> to add a work node to the k8s cluster del-etcd <cluster> <ip> to delete a etcd-node from the etcd cluster del-master <cluster> <ip> to delete a master node from the k8s cluster del-node <cluster> <ip> to delete a work node from the k8s cluster Extra operation: kcfg-adm <cluster> <args> to manage client kubeconfig of the k8s cluster Use "ezctl help <command>" for more information about a given command.
5、分步安装
自行修改参数配置
https://blog.csdn.net/qq_31055683/article/details/124208943
6、脚本一键安装
自行修改参数配置
https://blog.csdn.net/kwinh/article/details/125207267
7、安装环境
2CPU 4G
8、使用一键安装脚本安装
https://blog.csdn.net/kwinh/article/details/125207267
配置自己改
9、一键初始化master
[root@master1 ~]# ezctl setup test 04 ansible-playbook -i clusters/test/hosts -e @clusters/test/config.yml playbooks/04.kube-master.yml 2022-09-07 02:35:05 INFO cluster:test setup step:04 begins in 5s, press any key to abort: /root/.local/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release. from cryptography.exceptions import InvalidSignature PLAY [kube_master] ******************************************************************************************************************************************************************************************* TASK [Gathering Facts] *************************************************************************************************************************************************************************************** ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-lb : prepare some dirs] *************************************************************************************************************************************************************************** ok: [192.168.143.143] => (item=/etc/kube-lb/sbin) ok: [192.168.143.143] => (item=/etc/kube-lb/logs) ok: [192.168.143.142] => (item=/etc/kube-lb/sbin) ok: [192.168.143.143] => (item=/etc/kube-lb/conf) ok: [192.168.143.142] => (item=/etc/kube-lb/logs) ok: [192.168.143.142] => (item=/etc/kube-lb/conf) TASK [kube-lb : 下载二进制文件kube-lb(nginx)] **************************************************************************************************************************************************************** ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-lb : 创建kube-lb的配置文件] *********************************************************************************************************************************************************************** ok: [192.168.143.142] ok: [192.168.143.143] TASK [kube-lb : 创建kube-lb的systemd unit文件] *************************************************************************************************************************************************************** ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-lb : 开机启用kube-lb服务] ************************************************************************************************************************************************************************* changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-lb : 开启kube-lb服务] ***************************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-lb : 以轮询的方式等待kube-lb服务启动] ************************************************************************************************************************************************************* changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-master : 下载 kube_master 二进制] *********************************** ******************************************************************************** ********************************************** ok: [192.168.143.143] => (item=kube-apiserver) ok: [192.168.143.142] => (item=kube-apiserver) ok: [192.168.143.143] => (item=kube-controller-manager) ok: [192.168.143.142] => (item=kube-controller-manager) ok: [192.168.143.143] => (item=kube-scheduler) ok: [192.168.143.142] => (item=kube-scheduler) ok: [192.168.143.143] => (item=kubectl) ok: [192.168.143.142] => (item=kubectl) TASK [kube-master : 注册变量 KUBERNETES_SVC_IP] ************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-master : 设置变量 CLUSTER_KUBERNETES_SVC_IP] ****************************************************************************************************************************************************** ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-master : 创建 kubernetes 证书签名请求] ************************************************************************************************************************************************************ ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-master : 创建 kubernetes 证书和私钥] ************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-master : 创建 aggregator proxy证书签名请求] ******************************************************************************************************************************************************* ok: [192.168.143.142] ok: [192.168.143.143] TASK [kube-master : 创建 aggregator-proxy证书和私钥] ********************************************************************************************************************************************************* changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-master : 分发 kubernetes证书] ********************************************************************************************************************************************************************* ok: [192.168.143.142] => (item=ca.pem) ok: [192.168.143.143] => (item=ca.pem) ok: [192.168.143.142] => (item=ca-key.pem) ok: [192.168.143.143] => (item=ca-key.pem) changed: [192.168.143.142] => (item=kubernetes.pem) changed: [192.168.143.143] => (item=kubernetes.pem) changed: [192.168.143.142] => (item=kubernetes-key.pem) changed: [192.168.143.143] => (item=kubernetes-key.pem) changed: [192.168.143.142] => (item=aggregator-proxy.pem) changed: [192.168.143.143] => (item=aggregator-proxy.pem) changed: [192.168.143.142] => (item=aggregator-proxy-key.pem) changed: [192.168.143.143] => (item=aggregator-proxy-key.pem) TASK [kube-master : 替换 kubeconfig 的 apiserver 地址] ******************************************************************************************************************************************************* ok: [192.168.143.143] => (item=/root/.kube/config) ok: [192.168.143.142] => (item=/root/.kube/config) ok: [192.168.143.143] => (item=/etc/kubernetes/kube-controller-manager.kubeconfig) ok: [192.168.143.142] => (item=/etc/kubernetes/kube-controller-manager.kubeconfig) ok: [192.168.143.143] => (item=/etc/kubernetes/kube-scheduler.kubeconfig) ok: [192.168.143.142] => (item=/etc/kubernetes/kube-scheduler.kubeconfig) TASK [kube-master : 创建 master 服务的 systemd unit 文件] **************************************************************************************************************************************************** ok: [192.168.143.143] => (item=kube-apiserver.service) ok: [192.168.143.142] => (item=kube-apiserver.service) ok: [192.168.143.143] => (item=kube-controller-manager.service) ok: [192.168.143.142] => (item=kube-controller-manager.service) ok: [192.168.143.143] => (item=kube-scheduler.service) ok: [192.168.143.142] => (item=kube-scheduler.service) TASK [kube-master : enable master 服务] ********************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-master : 启动 master 服务] ************************************************************************************************************************************************************************ changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-master : 轮询等待kube-apiserver启动] ************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-master : 轮询等待kube-controller-manager启动] ***************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-master : 轮询等待kube-scheduler启动] ************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-master : 以轮询的方式等待master服务启动完成] ****************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-master : 获取user:kubernetes是否已经绑定对应角色] ************************************************************************************************************************************************* changed: [192.168.143.143] TASK [kube-master : 创建user:kubernetes角色绑定] ************************************************************************************************************************************************************* changed: [192.168.143.143] TASK [kube-node : 创建kube_node 相关目录] ******************************************************************************************************************************************************************** changed: [192.168.143.143] => (item=/var/lib/kubelet) changed: [192.168.143.142] => (item=/var/lib/kubelet) changed: [192.168.143.143] => (item=/var/lib/kube-proxy) changed: [192.168.143.142] => (item=/var/lib/kube-proxy) ok: [192.168.143.142] => (item=/etc/cni/net.d) ok: [192.168.143.143] => (item=/etc/cni/net.d) TASK [kube-node : 下载 kubelet,kube-proxy 二进制和基础 cni plugins] ****************************************************************************************************************************************** ok: [192.168.143.142] => (item=kubectl) ok: [192.168.143.143] => (item=kubectl) ok: [192.168.143.142] => (item=kubelet) ok: [192.168.143.143] => (item=kubelet) ok: [192.168.143.143] => (item=kube-proxy) ok: [192.168.143.142] => (item=kube-proxy) ok: [192.168.143.143] => (item=bridge) ok: [192.168.143.142] => (item=bridge) ok: [192.168.143.143] => (item=host-local) ok: [192.168.143.142] => (item=host-local) ok: [192.168.143.143] => (item=loopback) ok: [192.168.143.142] => (item=loopback) TASK [kube-node : 替换 kubeconfig 的 apiserver 地址] ********************************************************************************************************************************************************* ok: [192.168.143.142] ok: [192.168.143.143] TASK [kube-node : 准备kubelet 证书签名请求] ****************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 创建 kubelet 证书与私钥] ******************************************************************************************************************************************************************* changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 分发ca 证书] ******************************************************************************************************************************************************************************* ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-node : 分发kubelet 证书] ************************************************************************************************************************************************************************** changed: [192.168.143.143] => (item=kubelet.pem) changed: [192.168.143.142] => (item=kubelet.pem) changed: [192.168.143.143] => (item=kubelet-key.pem) changed: [192.168.143.142] => (item=kubelet-key.pem) TASK [kube-node : 设置集群参数] ****************************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 设置客户端认证参数] ************************************************************************************************************************************************************************ changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 设置上下文参数] **************************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 选择默认上下文] **************************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 准备 cni配置文件] ************************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 注册变量 DNS_SVC_IP] *********************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 设置变量 CLUSTER_DNS_SVC_IP] *************************************************************************************************************************************************************** ok: [192.168.143.143] ok: [192.168.143.142] TASK [kube-node : 创建kubelet的配置文件] ********************************************************************************************************************************************************************* changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 创建kubelet的systemd unit文件] ************************************************************************************************************************************************************* changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 开机启用kubelet 服务] ********************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 开启kubelet 服务] ************************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 替换 kube-proxy.kubeconfig 的 apiserver 地址] ********************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 创建kube-proxy 配置] *********************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 创建kube-proxy 服务文件] ******************************************************************************************************************************************************************* changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 开机启用kube-proxy 服务] ******************************************************************************************************************************************************************* changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 开启kube-proxy 服务] *********************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 轮询等待kube-proxy启动] ******************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 轮询等待kubelet启动] *********************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 轮询等待node达到Ready状态] ***************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 设置node节点role] ************************************************************************************************************************************************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 获取已下载离线镜像信息] ******************************************************************************************************************************************************************** changed: [192.168.143.142] changed: [192.168.143.143] TASK [kube-node : 尝试推送离线dnscache镜像(若执行失败,可忽略)] ************** ******************************************************************************** ********************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 获取dnscache离线镜像推送情况] ******************************** ******************************************************************************** ********************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [kube-node : 导入dnscache的离线镜像(若执行失败,可忽略)] **************** ******************************************************************************** ********************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [Making master nodes SchedulingDisabled] ********************************** ******************************************************************************** ********************************************** changed: [192.168.143.143] changed: [192.168.143.142] TASK [Setting master role name] ************************************************ ******************************************************************************** ********************************************** changed: [192.168.143.143] changed: [192.168.143.142] PLAY RECAP ********************************************************************* ******************************************************************************** ********************************************** 192.168.143.142 : ok=57 changed=42 unreachable=0 failed=0 s kipped=1 rescued=0 ignored=0 192.168.143.143 : ok=59 changed=44 unreachable=0 failed=0 s kipped=3 rescued=0 ignored=0
10、一键安装最终结果
11、一键安装问题
问题1、主机连接自己免密,如果执行脚本的主机也要加入集群节点
ssh-copy-id root@[执行脚本的主机IP]
https://blog.csdn.net/m0_67038390/article/details/125159680
问题2、centos7.9安装更新pip
https://blog.csdn.net/legend818/article/details/122361285
# 关键一步,这个针对2.7版本,3.X的不存在安装这个
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py python get-pip.py # 验证 pip list
https://blog.csdn.net/legend818/article/details/122361285
或者直接yum安装
yum -y install epel-release
yum install python-pip
https://blog.csdn.net/gwz_6903/article/details/100678333
https://blog.csdn.net/m0_54252387/article/details/125528212
问题3、python2.7 pip 升级报错 def read(rel_path: str) -> str:
wget https://files.pythonhosted.org/packages/0b/f5/be8e741434a4bf4ce5dbc235aa28ed0666178ea8986ddc10d035023744e6/pip-20.2.4.tar.gz #下载安装包 tar -zxvf pip-20.2.4.tar.gz # 解压 cd pip-20.2.4/ sudo python setup.py install #给予权限不然可能安装失败 pip install -U pip #再次更新
https://blog.csdn.net/Clovemeo/article/details/120191359
问题4、安装ansible报错“error in halo setup command: ‘install_requires‘ must be a string or list of”
pip install -U setuptools pip install --user -U setuptools # with --user flag
https://blog.csdn.net/chrisy521/article/details/124526282
问题5、centos7设置主机名,分别执行
hostnamectl set-hostname master1 hostnamectl set-hostname master2 hostnamectl set-hostname node1 hostnamectl set-hostname node2
https://blog.csdn.net/bakelff/article/details/121143315
问题6、链接其他主机配置免密登录
ssh-copy-id root@[其他主机ip]
https://blog.csdn.net/passible/article/details/124039087
问题7、配置网卡静态ip
https://www.cnblogs.com/lzkalislw/p/15696270.html
问题8、配置局域网/etc/hosts文件 ip和主机名解析
每台主机都加一下
192.168.143.142 master1 192.168.143.143 master2 192.168.143.140 node1 192.168.143.141 node2
参考链接:
https://blog.csdn.net/CarlZ42/article/details/125229815
https://blog.csdn.net/qq_31055683/article/details/124208943
https://blog.csdn.net/kwinh/article/details/125207267
http://shiyl.com/archives/ansible_install.html
https://blog.csdn.net/m0_64417032/article/details/125203949