<p>According to the <a href="https://doc.traefik.io/traefik/v1.7/configuration/backends/kubernetes/" rel="nofollow noreferrer">Traefik 1.7 documentation</a> you should be able to have Traefik perform a 302 redirect using:</p>
<ul>
<li><code>traefik.ingress.kubernetes.io/redirect-regex</code></li>
<li><code>traefik.ingress.kubernetes.io/redirect-replacement</code></li>
</ul>
<p>My goal is to simply remove the <code>www.</code> from the address.</p>
<p>This is what I've tried, but I get a 404 service not found.</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: www-redirect
  namespace: public
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/redirect-regex: ^https?://www.example.com/(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://example.com/$1
spec:
  rules:
  - host: www.example.com
</code></pre>
<p>Unfortunately the documentation isn't explicit on <em>how</em> to use them. At the time of writing the only google hit on this is the documentation (above).</p>
<p>My current work around (assuming it'll help explain the question) is to route <code>www.</code> traffic to nginx which returns a 302.</p>
<pre><code>server {
    listen       80;
    server_name  www.example.com;
    return 302 https://example.com$request_uri;
}
</code></pre>
<p>This seems like overkill.</p>


<p>I was having the same issue and ended up making it work with:</p>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: www-redirect
  namespace: public
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/preserve-host: "true"
    traefik.ingress.kubernetes.io/redirect-permanent: "true"
    traefik.ingress.kubernetes.io/redirect-regex: "^https://www.(.*)"
    traefik.ingress.kubernetes.io/redirect-replacement: "https://$1"
spec:
  tls:
    - hosts:
        - "example.com"
        - "www.example.com"
      secretName: example-tls
  rules:
  - host: example.com
  - host: www.example.com
</code></pre>

<p>Basically I needed both rules.</p>

<p>As a side note, I also start the trafik pod with the following flags:</p>

<pre><code>args:
   - --api
   - --kubernetes
   - --logLevel=INFO
   - --entryPoints=Name:https Address::443 TLS
   - --entrypoints=Name:http Address::80 Redirect.EntryPoint:https
   - --defaultentrypoints=https,http
</code></pre>
