master节点加入kubernetes单节点集群

一、k8s单节点集群加入master节点
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 ~]# 

2.将master1上的工作目录复制到master2

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

3.复制启动脚本到master2

[root@master1 ~]# scp /usr/lib/systemd/system/{kube-apiserver,kube-controller-manager,kube-scheduler}.service [email protected]:/usr/lib/systemd/system/
[email protected]'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

4.修改apiserver的ip地址,指向master2

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

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-03 11:25:45 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

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-03 11:27:36 CST; 12s ago

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-03 11:30:32 CST; 12s ago

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/

最后我们验证一下是否成功

[root@master2 cfg]# kubectl get nodes
NAME              STATUS   ROLES    AGE    VERSION
192.168.191.131   Ready       2d5h   v1.12.3
192.168.191.132   Ready       2d5h   v1.12.3