<p>I'm trying to deploy AWX on k3s and everything works just fine, however I'd like to enforce SSL - so, redirect HTTP to HTTPS.</p>
<p>I've been trying to test the SSL enforcement part, however it's not working properly. Here is my traefik config:</p>
<pre><code>apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
  name: traefik-crd
  namespace: kube-system
spec:
  chart: https://%{KUBERNETES_API}%/static/charts/traefik-crd-9.18.2.tgz
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
  name: traefik
  namespace: kube-system
spec:
  chart: https://%{KUBERNETES_API}%/static/charts/traefik-9.18.2.tgz
  set:
    global.systemDefaultRegistry: &quot;&quot;
  valuesContent: |-
    ssl:
      enforced: true
    rbac:
      enabled: true
    ports:
      websecure:
        tls:
          enabled: true
    podAnnotations:
      prometheus.io/port: &quot;8082&quot;
      prometheus.io/scrape: &quot;true&quot;
    providers:
      kubernetesIngress:
        publishedService:
          enabled: true
    priorityClassName: &quot;system-cluster-critical&quot;
    image:
      name: &quot;rancher/library-traefik&quot;
    tolerations:
    - key: &quot;CriticalAddonsOnly&quot;
      operator: &quot;Exists&quot;
    - key: &quot;node-role.kubernetes.io/control-plane&quot;
      operator: &quot;Exists&quot;
      effect: &quot;NoSchedule&quot;
    - key: &quot;node-role.kubernetes.io/master&quot;
      operator: &quot;Exists&quot;
      effect: &quot;NoSchedule&quot;
</code></pre>
<p>According to the Helm chart here <a href="https://github.com/helm/charts/tree/master/stable/traefik#configuration" rel="noreferrer">https://github.com/helm/charts/tree/master/stable/traefik#configuration</a>, the ssl.enforced parameter should do the trick however when I access my host using http it is still not redirecting me to https. I can see that Rancher is deploying a LB service for traefik as well, do I need to modify it somehow?</p>

dywan666
<p>I struggled myself to make redirection work, and finally found a working configuration.</p>
<p>You should define a Middleware object in kubernetes, and your Ingress object must reference it. Beware, because the documentation in traefik is very misleading here, because the Middleware manifest found on many pages forget the 'namespace' annotation, so they assure this is 'default' (which is stupid btw, no serious people work on default namespace).</p>
<p>Thus, here is a working configuration :</p>
<pre><code>apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: redirect
  namespace: some_namespace
spec:
  redirectScheme:
    scheme: https
    permanent: true
</code></pre>
<p>and</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wordpress
  namespace: your_app_namespace
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.middlewares: some_namespace-redirect@kubernetescrd
spec:
  tls:
    - secretName: your_certificate
      hosts:
        - www.your_website.com
  rules:
    - host: www.your_website.com
      http:
        paths:
          - path: /
            backend:
              service:
                name: your_service
                port:
                  number: 80
            pathType: ImplementationSpecific
</code></pre>
<p>So the trick is to :</p>
<ul>
<li>define a Middleware object (in any namespace you want, but that may be in the same one as your app)</li>
<li>reference it in <code>traefik.ingress.kubernetes.io/router.middlewares</code> with the syntax <code>&lt;NAMESPACE&gt;-&lt;NAME&gt;@kubernetescrd</code> (where NAMESPACE and NAME are those of the Middleware object)</li>
</ul>
