Search code examples
djangodockergoogle-kubernetes-enginekubernetes-ingressnginx-ingress

google cloud kubernetes ingress not redirecting to https


i deployed a django application in google cloud kubernetes, its all working i can access my site from https and use it. but when i type in the url the domain it opens with http, if i write https i can access too, i searched a lot and tried a lot of stuff in the internet still no success. there is a annotation

kubernetes.io/ingress.allowHTTP: "false" # <-- this one

this works disableing the http access, but i want to redirect to https not blocking, if i write in the browser url my domain it goes to http first. its all working the ssl and nginx ingress, i just can't redirect the access from http to https.

here is my nginx ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: django-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.global-static-ip-name: django-ip
    spec.ingressClassName: "nginx"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true" # <--- this one is not working
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/use-forwarded-headers: "true"
spec:
  tls:
    - hosts:
        - example-django.com
      secretName: django-certs
  defaultBackend:
    service:
      name: django-svc
      port: 
        name: django-core-http
  rules:
    - host: example-django.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: django-svc
                port:
                  name: django-core-http

tried annotations

kubernetes.io/ingress.allowHTTP: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"

installed nginx ingress with this https://kubernetes.github.io/ingress-nginx/deploy/#gce-gke


Solution

  • After try and error, i just moved from google cloud kubernetes to digital ocean and im loving it. It's all working properly