一步步安装部署kubernetes集群(三)3.3
3.3 配置nginx四层反向代理
3.3.1 集群规划
| 主机名 | 角色 | IP地址 |
|---|---|---|
| pg60-11.k8s.host.com | 4层负载均衡 | 10.20.60.11 |
| pg60-12.k8s.host.com | 4层负载均衡 | 10.20.60.12 |
注意:这里 10.20.60.11 和 10.20.60.12 使用nginx做4层负载均衡器,在keepalived上配置vip:10.20.60.10,代理两个 kube-apiserver,实现高可用。
3.3.2 编译安装Nginx
详见《源码安装openresty-1.11.2.5》
3.3.3 配置nginx vhost
shell> cat /opt/openresty/nginx/conf/nginx.conf
stream {
upstream kube-apiserver {
server 10.20.60.21:6443 max_fails=3 fail_timeout=30s;
server 10.20.60.22:6443 max_fails=3 fail_timeout=30s;
server 10.20.60.23:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 7443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}3.3.4 安装与配置keepalived
- 安装keepalived
shell> yum -y install keepalived
- 创建keepalived检查端口脚本check_port.sh
shell> cat /etc/keepalived/check_port.sh
#!/bin/bash
#keepalived 监控端口脚本
#使用方法:
#在keepalived的配置文件中
#vrrp_script check_port {#创建一个vrrp_script脚本,检查配置
# script "/etc/keepalived/check_port.sh 6379" #配置监听的端口
# interval 2 #检查脚本的频率,单位(秒)
#}
CHK_PORT=$1
if [ -n "$CHK_PORT" ];then
PORT_PROCESS=`ss -lnt|grep $CHK_PORT|wc -l`
if [ $PORT_PROCESS -eq 0 ];then
echo "Port $CHK_PORT Is Not Used,End."
exit 1
fi
else
echo "Check Port Cant Be Empty!"
fi- 配置keepalived(主)
shell> cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id 10.20.60.11
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_port.sh 7443"
interval 2
weight -20
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
mcast_src_ip 10.20.60.11
nopreempt
authentication {
auth_type PASS
auth_pass 11111111
}
track_script {
chk_nginx
}
virtual_ipaddress {
10.20.60.10
}
}- 配置keepalived(备)
shell> cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id 10.20.60.12
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_port.sh 7443"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
mcast_src_ip 10.20.60.12
authentication {
auth_type PASS
auth_pass 11111111
}
track_script {
chk_nginx
}
virtual_ipaddress {
10.20.60.10
}
}3.3.5 启动并检查服务
shell> systemctl start keepalived shell> systemctl enable keepalieve shell> /opt/openresty/nginx/sbin/nginx -s reload

相关推荐
MichelinMessi 2020-06-21
GenvenLiang 2020-06-15
Jaystrong 2020-06-10
zwmnhao0 2020-06-07
DriveCar 2020-06-06
CurrentJ 2020-05-28
极地雪狼 2020-05-15
后厂村老司机 2020-04-19
yongzhang 2020-05-11
快乐de馒头 2020-04-22
yungame 2020-04-21
快乐de馒头 2020-04-11
畅聊架构 2020-03-28
泥淖 2020-03-26
yevvzi 2020-03-01
xcznb 2020-02-28
sunnyxuebuhui 2020-02-16
OwenJi 2020-02-15
xiaobaif 2020-01-29