Kubernetes Ingress-Nginx实现高可用
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,假定我们在Kubernetes 指定两个worker节点中部署了ingress nginx来为后端的pod做proxy,这时候我们就需要通过keepalived实现高可用,提供对外的VIP首先我们要先
千家信息网最后更新 2025年12月01日Kubernetes Ingress-Nginx实现高可用
假定我们在Kubernetes 指定两个worker节点中部署了ingress nginx来为后端的pod做proxy,这时候我们就需要通过keepalived实现高可用,提供对外的VIP
首先我们要先确保有两个worker节点部署了ingress nginx
在本实验中,环境如下:
| IP地址 | 主机名 | 描述 |
|---|---|---|
| 10.0.0.31 | k8s-master01 | |
| 10.0.0.34 | k8s-node02 | ingress nginx、keepalived |
| 10.0.0.35 | k8s-node03 | ingress nginx、keepalived |
1、查看ingress nginx状态
[root@k8s-master01 Ingress]# kubectl get pod -n ingress-nginx -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx-ingress-controller-85bd8789cd-8c4xh 1/1 Running 0 62s 10.0.0.34 k8s-node02 nginx-ingress-controller-85bd8789cd-mhd8n 0/1 Pending 0 3s nginx-ingress-controller-85ff8dfd88-vqkhx 1/1 Running 0 3m56s 10.0.0.35 k8s-node03 创建一个用于测试环境的namespace
kubectl create namespace test2、部署一个Deployment(用于测试)
apiVersion: apps/v1kind: Deploymentmetadata: name: myweb-deploy # 部署在测试环境 namespace: testspec: replicas: 3 selector: matchLabels: name: myweb type: test template: metadata: labels: name: myweb type: test spec: containers: - name: nginx image: nginx:1.13 imagePullPolicy: IfNotPresent ports: - containerPort: 80---# serviceapiVersion: v1kind: Servicemetadata: name: myweb-svcspec: selector: name: myweb type: test ports: - port: 80 targetPort: 80 protocol: TCP---# ingress执行kubectl create 创建deployment
kubectl create -f myweb-demo.yaml查看deployment是否部署成功
[root@k8s-master01 Project]# kubectl get pods -n test -o wide | grep "myweb"myweb-deploy-6d586d7db4-2g5ll 1/1 Running 0 23s 10.244.3.240 k8s-node02 myweb-deploy-6d586d7db4-cf7w7 1/1 Running 0 4m2s 10.244.1.132 k8s-node01 myweb-deploy-6d586d7db4-rp5zc 1/1 Running 0 3m59s 10.244.2.5 k8s-node03 3、在两个worker节点部署keepalived
VIP:10.0.0.130,接口:eth0
1.安装keepalived
yum -y install keepalived1.k8s-node03节点作为master配置keepalived
[root@k8s-node03 ~]# cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs { notification_email_from Alexandre.Cassen@firewall.loc router_id k8s-node03 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0}vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 110 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.130/24 dev eth0 label eth0:1 }}2.k8s-node03节点作为配置keepalived
[root@k8s-node03 ~]# cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs { router_id k8s-node03 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0}vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 110 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.130/24 dev eth0 label eth0:1 }}3.k8s-node02节点配置keeplived
[root@k8s-node02 ~]# cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs { router_id k8s-node02 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0}vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.130/24 dev eth0 label eth0:1 }}4.两个节点启动keepalived并加入开机启动
systemctl start keepalived.servicesystemctl enable keepalived.service 启动完成后检查k8s-node03的IP地址是否已有VIP
[root@k8s-node03 ~]# ip add | grep "130" inet 10.0.0.130/24 scope global secondary eth0:15.在宿主机上配置hosts文件,实现IP和域名的解析
10.0.0.130 myweb.app.com6.浏览器测试访问
4.测试vip漂移
现在我将k8s-node03的keepalived进程关闭,那么vip就会漂移到k8s-node02
[root@k8s-node03 ~]# systemctl stop keepalived.service// 在k8s-node02上查看VIP[root@k8s-node02 ~]# ip add | grep "130" inet 10.0.0.130/24 scope global secondary eth0:1再次访问
节点
测试
两个
配置
环境
地址
成功
主机
再次
域名
宿主
接口
文件
浏览器
状态
端的
进程
实验
对外
检查
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
英语网络安全的作文万能词汇
公司面临的三个网络安全问题
农业农村部网络安全与信息化
单路网络视频服务器
东莞信息安全学习网络安全
苹果手机加密软件开发
tbc联盟pve服务器
浦东新区网络技术服务售后服务
服务器配置管理器启动不起来
个人如何进行网络安全工作
扬农国家网络安全
合肥本科生找软件开发
哪个公司的数据库备份mysql
苏州进口刀片服务器施工
c语言调用数据库进行操作
云核网络技术
服务器cup3104
腾讯qq数据库
赛灵思推服务器一体机
app后端用什么软件开发
数据库读取数据jsp
2020网络安全调查问卷
linux服务器开发中网络分析
网络安全密钥一般密码
中国移动3g网络技术
综合系统管理软件开发
数据库哪些操作需要维护索引
金山区机械软件开发定制价格
能够检索学位论文数据库
服务器采购技术参数