备注:首先在原先的apisever证书设置中要预先加入想要新增的master节点IP,这样就不需要再重新申请证书

一定要把networkmanager关掉

kubeconfig

kubelet 提交证书请求给master——apiserver——记录到etcd

proxy 网络代理、负载均衡

部署多节点master的k8s集群需要先具备单master节点的部署环境

一:k8s单节点集群加入master节点

1.1优先关闭防火墙(或者开启所需端口)和selinux服务

[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname master2
[root@localhost ~]# su
[root@master2 ~]# systemctl stop NetworkManager
[root@master2 ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.
[root@master2 ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@master2 ~]# iptables -F
[root@master2 ~]# 

1.2 从master1上复制工作目录到master2

备注:master2也要有etcd的证书

[root@master1 ~]# scp -r /k8s root@192.168.247.148:/k8s
[root@master2 k8s]# ls
bin  cfg  etcd  ssl

1.3 复制启动脚本

[root@master1 ~]# scp /usr/lib/systemd/system/{kube-apiserver,kube-controller-manager,kube-scheduler}.service root@192.168.247.148:/usr/lib/systemd/system/
root@192.168.247.148's password: 
kube-apiserver.service                                           100%  260   102.1KB/s   00:00    
kube-controller-manager.service                                  100%  295    46.0KB/s   00:00    
kube-scheduler.service                                           100%  259    88.8KB/s   00:00  

1.4 修改关于apiserver的IP地址,从master1指向master2

[root@master1 cfg]# ls
kube-apiserver  kube-controller-manager  kube-scheduler  token.csv
[root@master2 cfg]# vim kube-apiserver 
--bind-address=192.168.247.148 \
--advertise-address=192.168.247.148 \
[root@master2 cfg]# vim kube-controller-manager 
[root@master2 cfg]# vim kube-scheduler 

1.5 开启apiserver

[root@master2 cfg]# systemctl start kube-apiserver.service 
[root@master2 cfg]# systemctl status kube-apiserver.service 
● kube-apiserver.service - Kubernetes API Server
   Loaded: loaded (/usr/lib/systemd/system/kube-apiserver.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-02 17:26:30 CST; 4s ago
     Docs: https://github.com/kubernetes/kubernetes
 Main PID: 21187 (kube-apiserver)
 [root@master2 cfg]# systemctl enable kube-apiserver.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-apiserver.service to /usr/lib/systemd/system/kube-apiserver.service.

1.6 开启scheduler

[root@master2 cfg]# systemctl start kube-scheduler.service 
[root@master2 cfg]# systemctl enable kube-scheduler.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-scheduler.service to /usr/lib/systemd/system/kube-scheduler.service.
[root@master2 cfg]# systemctl status kube-scheduler.service 
● kube-scheduler.service - Kubernetes Scheduler
   Loaded: loaded (/usr/lib/systemd/system/kube-scheduler.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-02 17:27:32 CST; 12s ago

1.7 开启controllet-manager

[root@master2 cfg]# systemctl start kube-controller-manager.service 
[root@master2 cfg]# systemctl enable kube-controller-manager.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-controller-manager.service to /usr/lib/systemd/system/kube-controller-manager.service.
[root@master2 cfg]# systemctl status kube-controller-manager.service 
● kube-controller-manager.service - Kubernetes Controller Manager
   Loaded: loaded (/usr/lib/systemd/system/kube-controller-manager.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-02 17:28:32 CST; 12s ago

1.8 添加环境变量

[root@master2 cfg]# echo "PATH=$PATH:/k8s/bin/" >> /etc/profile
[root@master2 cfg]# source /etc/profile
[root@master2 cfg]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/k8s/bin/

1.9 验证

[root@master2 cfg]# kubectl get nodes
NAME              STATUS   ROLES    AGE    VERSION
192.168.247.143   Ready    <none>   2d5h   v1.12.3
192.168.247.144   Ready    <none>   2d5h   v1.12.3

此时多节点master搭建完毕

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐