Skip to content

Instantly share code, notes, and snippets.

@thomasstxyz
Last active December 1, 2022 18:26
Show Gist options
  • Save thomasstxyz/551fb0642dc635930e84959f3bbc517a to your computer and use it in GitHub Desktop.
Save thomasstxyz/551fb0642dc635930e84959f3bbc517a to your computer and use it in GitHub Desktop.
Redirect HTTP to HTTPS for the default Ingress controller Traefik for K3s

To enable redirection, you need to deploy a middleware with redirectScheme.

Since this can be referenced from other namespaces, you will create it in the default namespace for ease of sharing.

cat <<EOF > middleware.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: http-redirect
spec:
  redirectScheme:
    scheme: https
    permanent: true
EOF

kubectl -n default apply -f middleware.yaml
kubectl -n default get middleware

To enable redirection, the Ingress resource must have the following annotation.

  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: default-http-redirect@kubernetescrd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment