traefik 2.x WRR带权重的轮训实验

没有装traefik 2.x的先看我之前的traefik 2.x安装文档。

一共4个yaml,按顺序执行。

01-appv1.yaml

02-appv2.yaml

03-app-ingress-route.yaml

04-wrr.yaml

# 分别执行四个文件
$ kubectl apply -f xxx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appv1
spec:
  selector:
    matchLabels:
      app: appv1
  template:
    metadata:
      labels:
        use: test
        app: appv1
    spec:
      containers:
        - name: whoami
          image: containous/whoami
          ports:
            - containerPort: 80
              name: portv1

---
apiVersion: v1
kind: Service
metadata:
  name: appv1
spec:
  selector:
    app: appv1
  ports:
    - name: http
      port: 80
      targetPort: portv1
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appv2
spec:
  selector:
    matchLabels:
      app: appv2
  template:
    metadata:
      labels:
        use: test
        app: appv2
    spec:
      containers:
        - name: nginx
          image: nginx:1.8
          ports:
            - containerPort: 80
              name: portv2

---
apiVersion: v1
kind: Service
metadata:
  name: appv2
spec:
  selector:
    app: appv2
  ports:
    - name: http
      port: 80
      targetPort: portv2
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: wrringressroute
  namespace: default
spec:
  # 同时支持http和https访问
  entryPoints:
    - web
  routes:
    - match: Host(`wrr.duliri.com`)
      kind: Rule
      services:
        - name: app-wrr
          kind: TraefikService
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
  name: app-wrr
spec:
  weighted:
    services:
      - name: appv1
        weight: 3  # 定义权重
        port: 80
        kind: Service  # 可选,默认就是 Service
      - name: appv2
        weight: 1
        port: 80
# 1. hosts添加解析
yourNodeIp wrr.duliri.com

# 2. curl请求多次接口,查看访问权重是否符合设置
$ curl http://wrr.duliri.com:30001

 访问4此,3次请求到appv1,1次访问到appv2,查看traefik dashboard权重页面

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值