<p>I'm looking to redirect all traffic from </p>

<p><a href="http://example.com" rel="noreferrer">http://example.com</a> -> <a href="https://example.com" rel="noreferrer">https://example.com</a> like how nearly all websites do.</p>

<p>I've looked at this link with no success:
<a href="https://stackoverflow.com/questions/40763718/kubernetes-https-ingress-in-google-container-engine">Kubernetes HTTPS Ingress in Google Container Engine</a></p>

<p>And have tried the following annotations in my ingress.yaml file.</p>

<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  if ($http_x_forwarded_proto != 'https') {
    return 301 https://$host$request_uri;
  }
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/ingress.allow-http: "false"
</code></pre>

<p>All without any success. To be clear, I can access <a href="https://example.com" rel="noreferrer">https://example.com</a> and  <a href="http://example.com" rel="noreferrer">http://example.com</a> without any errors, I need the http call to redirect to https. </p>

<p>Thanks</p>

<p>GKE uses GCE L7. The rules that you referenced in the example are not supported and the HTTP to HTTPS redirect should be controlled at the application level.</p>

<p>L7 inserts the <code>x-forwarded-proto</code> header that you can use to understand if the frontend traffic came using HTTP or HTTPS. Take a look here: <a href="https://github.com/kubernetes/ingress-gce/blob/master/README.md#redirecting-http-to-https" rel="noreferrer">Redirecting HTTP to HTTPS</a></p>

<p>There is also an example in that link for Nginx (copied for convenience):</p>

<pre><code># Replace '_' with your hostname.
server_name _;
if ($http_x_forwarded_proto = "http") {
    return 301 https://$host$request_uri;
}
</code></pre>
