I'm after a very simple requirement - yet seems impossible to make Traefik redirect traffic from HTTP to HTTPS when behind an external load balancer.
This is my GCE ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: platform
name: public-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: "kubernetes-cluster-dev-ip"
kubernetes.io/ingress.class: "gce"
ingress.gcp.kubernetes.io/pre-shared-cert: "application-dev-ssl,application-dev-graphql-ssl"
spec:
backend:
serviceName: traefik-ingress-service
servicePort: 80
Which receive traffic from HTTP(S) then forward to Traefik to port 80.
I initially tried to using Traefik way of redirecting matching the schema with this configuration:
[entryPoints]
[entryPoints.http]
address = ":80"
compress = true
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
compress = true
[entryPoints.https.tls]
But obviously gets into an infinite redirect loop because of the load balancer always proxy traffic to Traefik port 80.
The simple solution to make this work is exactly what GCE suggests https://github.com/kubernetes/ingress-gce#ingress-cannot-redirect-http-to-https
Being able to check for the http_x_forwarded_proto
header and redirect based on that.
Nginx equivalent
# Replace '_' with your hostname.
server_name _;
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
Can someone advice what's the best way of handling this with Traefik, please!