Traefik Middleware

安装一个测试用的nginx

给这个 deploy 安装一个 svc

创建对应的 Traefik service 和 Ingress route

 apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ngingressroute
  namespace: lizhe
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`ngts.lizhe.com`)
    kind: Rule
    services:
    - name: ngts
      kind: TraefikService
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
  name: ngts
  namespace: lizhe
spec:
  weighted:
    services:
      - name: nginxsvc
        port: 80
        kind: Service

创建一个 middleware

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: test-ipwhitelist
  namespace: lizhe
spec:
  ipWhiteList:
    sourceRange:
      - 127.1.1.1/32
      - 192.1.1.1/32

然后需要修改一下 route ,让route使用这个新创建的 middleware

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ngingressroute
  namespace: lizhe
spec:
  entryPoints:
    - web
  routes:
  routes:
  - middlewares:
      - name: test-ipwhitelist
    match: Host(`ngts.lizhe.com`)
    kind: Rule
    services:
    - name: ngts
      kind: TraefikService

更新一下这个白名单,打开 本机 ip

这里不需要重启,就可以看见已经生效了

Send a Message