<p>I have the following YAML (test.yaml) file that allows me to create ingress router and middleware for traefik 2</p>
<pre><code>apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: test
  namespace: qa
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`my-url.com`) &amp;&amp; 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
</code></pre>
<p>Following files works. However, when I try to remove it using the following command:</p>
<pre><code>kubectl delete -f test.yaml
</code></pre>
<p>Traefik complains that middleware and ingress router is not preset. Example of error as follows:</p>
<pre><code>time=&quot;2021-07-09T18:15:12Z&quot; level=error msg=&quot;middleware \&quot;qa-test@kubernetescrd\&quot; does not exist&quot; routerName=qa-test-29c010046e0ec473d890@kubernetescrd entryPointName=web 
time=&quot;2021-07-09T18:15:25Z&quot; level=error msg=&quot;middleware \&quot;qa-test@kubernetescrd\&quot; does not exist&quot; entryPointName=web routerName=qa-test-29c010046e0ec473d890@kubernetescrd 
time=&quot;2021-07-09T18:15:25Z&quot; level=error msg=&quot;middleware \&quot;qa-test@kubernetescrd\&quot; does not exist&quot; entryPointName=web routerName=qa-test-29c010046e0ec473d890@kubernetescrd 
time=&quot;2021-07-09T18:31:44Z&quot; level=error msg=&quot;middleware \&quot;qa-test@kubernetescrd\&quot; does not exist&quot; entryPointName=web routerName=qa-test-29c010046e0ec473d890@kubernetescrd
</code></pre>
<p>Do you know how to remove middleware and ingress routers without error?</p>

<p>Try editing the IngressRoute to remove Middleware from IngressRoute first and then delete the Middleware and then the IngressRoute.</p>
<pre><code>kubectl edit ingressroute test -n qa; 
kubectl delete middleware testmiddle -n qa; 
kubectl delete ingressroute test -n qa
</code></pre>
<p>since these are crd's, API-server won't delete them in the right order when deleting from a file and you would see error messages in the logs.</p>
