2

I've tried everything on stack overflow and beyond and can't find a solution that works to redirect http to https. My current config is below.

My ingress is:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/ingress.global-static-ip-name: my-address
    networking.gke.io/managed-certificates: my-certificate
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
spec:
  rules:
  - host: mydomain.com
    http:
      paths:
      - path: /*
        pathType: ImplementationSpecific
        backend:
          service:
            name: my-service
            port:
              number: 2400

And my service is:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: nodeweb
  ports:
  - name: my-service-port
    protocol: TCP
    port: 2400
    targetPort: 2400
nickponline
  • 25,354
  • 32
  • 99
  • 167

1 Answers1

2

For GKE (1.17.13-gke.2600+), find this document explaining how to configure FrontendConfig with http-to-https redirect. Then you associate the FrontendConfig with your Ingress using networking.gke.io/v1beta1.FrontendConfig annotation.

jabbson
  • 4,390
  • 1
  • 13
  • 23
  • Do I need to keep all the existing annotations I have in my current Ingress config? – nickponline Nov 28 '21 at 02:56
  • I'd revert back to the embedded ingress controller, unless you need specifically nginx for some of its functionality. – jabbson Nov 28 '21 at 02:57
  • Thanks @jabbson this works for redirecting http:// example.com to https:// example.com however http:// www.example.com gives an error "response 404 (backend NotFound), service rules for the path non-existent " - where as https:// www.example.com correctly goes to https:// example.com – nickponline Nov 28 '21 at 18:36