相关内容:
Kubernetes部署(一):架构及功能说明
Kubernetes部署(二):系统环境初始化
Kubernetes部署(三):CA证书制作
Kubernetes部署(四):ETCD集群部署
Kubernetes部署(五):Haproxy、Keppalived部署
Kubernetes部署(六):Master节点部署
Kubernetes部署(七):Node节点部署
Kubernetes部署(八):Flannel网络部署
Kubernetes部署(九):CoreDNS、Dashboard、Ingress部署
Kubernetes部署(十):储存之glusterfs和heketi部署
Kubernetes部署(十一):管理之Helm和Rancher部署
Kubernetes部署(十二):helm部署harbor企业级镜像仓库
部署haproxy
1. 安装haproxy
[root@node-01 ~]# yum install haproxy -y
2. 配置内核转发
基于NAT模式的负载均衡器都需要打开系统转发功能
[root@node-01 ~]# cat >>/etc/sysctl.conf<
3. 日志配置
编辑/etc/rsyslog.conf增加如下配置
cat >>/etc/rsyslog.conf <
vim /etc/rsyslog.conf +15 #取消配置文件注释
$ModLoad imudp
$UDPServerRun 514
编辑/etc/sysconfig/rsyslog
[root@node-01 ~]# tail -1 /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-c 2 -m 0 -r -x"
#重启rsyslog服务
systemctl restart rsyslog
在node-01和node-02执行相同操作,注意修改部分配置的ip地址
4. haproxy配置
node-01配置和node-2配置一样
[root@node-01 ~]# vim /etc/haproxy/haproxy.cfg
global
chroot /var/lib/haproxy
daemon
group haproxy
user haproxy
log 127.0.0.1:514 local0 warning
pidfile /var/lib/haproxy.pid
maxconn 20000
spread-checks 3
nbproc 8
defaults
log global
mode tcp
retries 3
option redispatch
listen https-apiserver
bind 10.31.90.200:6443
mode tcp
balance roundrobin
timeout server 15s
timeout connect 15s
server apiserver01 10.31.90.201:6443 check port 6443 inter 5000 fall 5
server apiserver02 10.31.90.202:6443 check port 6443 inter 5000 fall 5
server apiserver03 10.31.90.203:6443 check port 6443 inter 5000 fall 5
listen http-apiserver
bind 10.31.90.200:8080
mode tcp
balance roundrobin
timeout server 15s
timeout connect 15s
server apiserver01 10.31.90.201:8080 check port 8080 inter 5000 fall 5
server apiserver02 10.31.90.202:8080 check port 8080 inter 5000 fall 5
server apiserver03 10.31.90.203:8080 check port 8080 inter 5000 fall 5
5. 启动服务
[root@node-01 ~]# systemctl start haproxy.service
[root@node-01 ~]# systemctl status haproxy.service
部署Keepalived
1. 安装keepalived
[root@node-01 k8s]# tar zxf keepalived-2.0.10.tar.gz
[root@node-01 k8s]# cd keepalived-2.0.10/
[root@node-01 keepalived-2.0.10]# ./configure
[root@node-01 keepalived-2.0.10]# make -j2 && make install
[root@node-01 keepalived-2.0.10]#mkdir /etc/keepalived
[root@node-01 keepalived-2.0.10]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@node-01 keepalived-2.0.10]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
2. 日志配置
修改/etc/sysconfig/keepalived
[root@node-01 keepalived-2.0.10]# vim /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -d -S 1"
cat >>/etc/rsyslog.conf <
#重启rsyslog服务
systemctl restart rsyslog
3. keepalived配置文件
node-01配置文件
[root@node-01 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 50
advert_int 1
priority 100
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.31.90.200/24
}
}
node-02配置文件
[root@node-02 keepalived-2.0.10]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 50
advert_int 1
priority 90
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.31.90.200/24
}
}
至此haproxy和keepalived部署完成,可以停止其中一台的keepalived服务器,用ip add show eth0
查看VIP的漂浮状态,如果能正常转移就成功了。
#node-01
[root@node-01 ~]# ip add show eth0
2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:82:64:70 brd ff:ff:ff:ff:ff:ff
inet 10.31.90.201/24 brd 10.31.90.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 10.31.90.200/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe82:6470/64 scope link noprefixroute
valid_lft forever preferred_lft forever
#node-02
[root@node-02 ~]# ip add show eth0
2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:82:dd:7d brd ff:ff:ff:ff:ff:ff
inet 10.31.90.202/24 brd 10.31.90.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe82:dd7d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
后续会陆续更新所有的安装文档,如果你觉得我写的不错,希望大家多多关注点赞,非常感谢!