k8s- nginx ingress 高可用部署(最新版,支持 k8s 1.22---1.19)第3篇 测试

第一,测试VIP漂移

1、查看 vip 是否绑定成功

打开 安装了  keeplived的MASTER主节点机器,  

ip  addr

 

ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP 
group default qlen 1000
 link/ether 00:0c:29:79:9e:36 brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.62/24 brd 192.168.40.255 scope global noprefixroute ens33
 valid_lft forever preferred_lft forever
 inet 192.168.1.199/24 scope global secondary ens33
...

看到  "inet 192.168.1.199/24 scope global secondary ens33" 类似这样,说明成功了。

 

2、测试vip漂移

(1) 停止 keeplived的主节点,VIP会漂移到备份节点

service keepalived stop

(2)开始Keeplived的主节点,VIP又会漂移回主节点。

service keepalived start

 

 

第二、测试 Ingress HTTP 代理 k8s 内部站点

 

k8s的master节点上创建一个pod,和ingress. yaml文件如下:

apiVersion: v1
kind: Service
metadata:
  name: tomcat
  namespace: default
spec:
  selector:
    app: tomcat
    release: canary
  ports:
  - name: http
    targetPort: 8080
    port: 8080
  - name: ajp
    targetPort: 8009
    port: 8009
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deploy
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: tomcat
      release: canary
  template:
    metadata:
      labels:
        app: tomcat
        release: canary
    spec:
      containers:
      - name: tomcat
        image: tomcat:8.5.34-jre8-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 8080
          name: ajp
          containerPort: 8009

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-myapp
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: tomcat.lucky.com
    http:
      paths:
      - path: /
        pathType:  Prefix
        backend:
         service:
           name: tomcat
           port:
            number: 8080

 

我们看到 ingress的域名设置为   tomcat.lucky.com  。

本地host添加

192.168.157.199  tomcat.lucky.com

然后访问 http://tomcat.lucky.com/,通了,说明已经安装成功了。

 

 

 

教程中涉及到的文件可以下载:

 

链接:https://pan.baidu.com/s/1oRvhN2_nfVT2ndE2VEN2QQ
提取码:muxx 

 

posted @ 2021-12-08 01:05  沐雪架构师  阅读(701)  评论(0编辑  收藏  举报