部署后如何在 kubernetes 中删除 Traefik 2.0 中间件和 IngressRoute

How to remove Traefik 2.0 Middleware and IngressRoute in kubernetes once deployed

我有以下 YAML (test.yaml) 文件,它允许我为 traefik 2 创建入口路由器和中间件

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: test
  namespace: qa
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`my-url.com`) && PathPrefix(`/test`)
      kind: Rule
      services:
        - name: test
          port: 8000
      middlewares:
        - name: testmiddle
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: testmiddle
  namespace: qa
spec:
  stripPrefix:
    prefixes:
      - /test

以下文件有效。但是,当我尝试使用以下命令删除它时:

kubectl delete -f test.yaml

Traefik 抱怨中间件和入口路由器没有预设。错误示例如下:

time="2021-07-09T18:15:12Z" level=error msg="middleware \"qa-test@kubernetescrd\" does not exist" routerName=qa-test-29c010046e0ec473d890@kubernetescrd entryPointName=web 
time="2021-07-09T18:15:25Z" level=error msg="middleware \"qa-test@kubernetescrd\" does not exist" entryPointName=web routerName=qa-test-29c010046e0ec473d890@kubernetescrd 
time="2021-07-09T18:15:25Z" level=error msg="middleware \"qa-test@kubernetescrd\" does not exist" entryPointName=web routerName=qa-test-29c010046e0ec473d890@kubernetescrd 
time="2021-07-09T18:31:44Z" level=error msg="middleware \"qa-test@kubernetescrd\" does not exist" entryPointName=web routerName=qa-test-29c010046e0ec473d890@kubernetescrd

你知道如何正确删除中间件和入口路由器吗?

尝试编辑 IngressRoute 以先从 IngressRoute 中删除中间件,然后删除中间件,然后再删除 IngressRoute。

kubectl edit ingressroute test -n qa; 
kubectl delete middleware testmiddle -n qa; 
kubectl delete ingressroute test -n qa

因为这些是 crd,API-server 在从文件中删除时不会以正确的顺序删除它们,您会在日志中看到错误消息。