k8s多master节点部署(实验)
文章目录
- k8s多master节点部署(实验)
- 前言
- 1. 多节点的部署
- 2. 搭建nginx负载均衡
- 3. 配置keepalived高可用服务
- 4. 修改两个node节点
- 5. 测试
前言
- 上节,我们部署了k8s的单节点,主要的核心点就是证书的创建和颁发,flannel网络组件也是相当重要的。本文主要是基于单master节点的部署(https://blog.csdn.net/double_happy111/article/details/105858003)来升级并部署的。
1. 多节点的部署
- 部署master02节点
- 复制kubernetes目录下面的所有文件
[root@localhost kubeconfig]
[root@localhost kubeconfig]
[root@master2 ~]
[root@master2 cfg]
kube-apiserver kube-controller-manager kube-scheduler token.csv
[root@master2 cfg]
--bind-address=192.168.73.62
--advertise-address=192.168.73.62
- 拷贝master01上已有的etcd证书给master2使用
[root@master1 ~]
[email protected]'s password:
etcd 100% 523 326.2KB/s 00:00
etcd 100% 18MB 45.1MB/s 00:00
etcdctl 100% 15MB 33.0MB/s 00:00
ca-key.pem 100% 1679 160.2KB/s 00:00
ca.pem 100% 1265 592.6KB/s 00:00
server-key.pem 100% 1679 884.2KB/s 00:00
server.pem 100% 1338 768.5KB/s 00:00
//开启 apiserver 组件
[root@master2 cfg]
[root@master2 cfg]
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-apiserver.service to /usr/lib/systemd/system/kube-apiserver.service.
////开启 controller-manager 组件
[root@master2 cfg]
[root@master2 cfg]
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-controller-manager.service to /usr/lib/systemd/system/kube-controller-manager.service.
//开启 scheduler 组件
[root@master2 cfg]
[root@master2 cfg]
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-scheduler.service to /usr/lib/systemd/system/kube-scheduler.service.
[root@master2 cfg]
在末尾添加:
export PATH=$PATH:/opt/kubernetes/bin/
[root@master2 cfg]
[root@localhost cfg]
NAME STATUS ROLES AGE VERSION
192.168.73.63 Ready <none> 50m v1.12.3
192.168.73.64 Ready <none> 22s v1.12.3
2. 搭建nginx负载均衡
[root@localhost ~]
[root@localhost ~]
//编写repo文件
[root@localhost ~]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enable=1
[root@localhost ~]
[root@localhost ~]
在events模块下添加以下内容:日志格式、日志存放位置、upstream模块
stream {
log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';
access_log /var/log/nginx/k8s-access.log main;
upstream k8s-apiserver {
server 192.168.73.61:6443;
server 192.168.73.62:6443;
}
server {
listen 6443;
proxy_pass k8s-apiserver;
}
}
//检查配置文件是否有语法错误
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
3. 配置keepalived高可用服务
[root@localhost ~]
[root@nginx1 ~]
//删除配置文件全部内容,添加以下内容:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id NGINX_MASTER
}
vrrp_script check_nginx {
script "/etc/nginx/check_nginx.sh"
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.100/24
}
track_script {
check_nginx
}
}
[root@nginx2 ~]
//删除配置文件全部内容,添加以下内容:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id NGINX_SLAVE
}
vrrp_script check_nginx {
script "/etc/nginx/check_nginx.sh"
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.100/24
}
track_script {
check_nginx
}
}
[root@localhost ~]
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
systemctl stop keepalived
fi
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
4. 修改两个node节点
//修改内容:server: https://192.168.100.100:6443(都改成vip地址)
[root@localhost cfg]
[root@localhost cfg]
[root@localhost cfg]
[root@localhost cfg]
[root@localhost cfg]
//确保必须在此路径下 grep 检查
[root@localhost ~]
[root@localhost cfg]
[root@localhost ~]
5. 测试
[root@localhost kubeconfig]
[root@master1 ~]
NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-vj4wk 1/1 Running 0 16s
此时已经创建完成,正在运行中。
[root@master1 ~]
Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) ( pods/log nginx-dbddb74b8-vj4wk)
解决办法(添加匿名用户授予权限):
[root@master1 ~]
clusterrolebinding.rbac.authorization.k8s.io/cluster-system-anonymous created
此时,再次查看日志,就不会出现报错,但是没有信息产生,因为没有访问容器。
[root@localhost kubeconfig]