Redirection from http to https not working for custom backend service in Kubernetes Nginx Ingress Controller

Alen T Mathew

I have setup Custom Nginx ingress controller with Ingress resource in Kubernetes and instead of "default-http-backend service", I used custom application as the default backend service to be served for default requests. I have also used custom SSL which is set as kubernetes secret, for my service. The issue is that when I request the hostnames which are mentioned in the rules, the https redirection works. But when the requests other than the hosts mentioned in the rules are made, it serves the default app, but the https redirection does not work.

How can I redirect requests from http to https for all the requests including default requests. In other words, how to setup https redirection for wildcard domains in ingress resource.

Please find my yaml files for ingress resource.

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-resource
  namespace: default
  annotations:
   kubernetes.io/ingress.class: "nginx"
   kubernetes.io/ingress.allow-http: "false"
   ingress.kubernetes.io/rewrite-target: /
   ingress.kubernetes.io/ssl-redirect: "true"
   ingress.kubernetes.io/proxy-connect-timeout: "14400"
   ingress.kubernetes.io/proxy-send-timeout: "14400"
   ingress.kubernetes.io/proxy-read-timeout: "14400"
spec:
  tls:
  - secretName: tls-secret

  rules:

  - host: service1.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: service1
          servicePort: 80

  - host: service2.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: service2
          servicePort: 80

---
Alen T Mathew

I needed to configure custom service (not default-http-backend service) for default requests which does not have rules set and this custom service should use custom SSL. At present nginx-ingress-controller doesn't do anything if the domain names are omitted from the Ingress rules (with the intention of the "wildcard" TLS cert being used). Therefore I have added the following code in the ingress yaml I used and this works perfectly. I have added the wildcard tls name in ingress rules at the bottom for the custom default service. Please find the code below:

  rules:

  - host: service1.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: service1
          servicePort: 80

  - host: service2.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: service2
          servicePort: 80

  - host: '*.example.com'
    http:
      paths:
      - path: /
        backend:
          serviceName: custom-backend-service
          servicePort: 80

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to debug Kubernetes nginx Ingress redirection from HTTP to HTTPS

HTTPS redirect not working for default backend of nginx-ingress-controller

Ability to exclude one page from https redirection in nginx ingress controller

Ingress controller nginx kubernetes not working

kubernetes ingress controller with cluster ip service and default nginx not working as expected

kubernetes nginx ingress fails to redirect HTTP to HTTPS

Exposing service from Kubernetes NGINX Ingress controller always return 502 Bad Gateway

Want (internal) name for service while running nginx ingress controller kubernetes

Kubernetes Nginx Ingress HTTP to HTTPS redirect via 301 instead of 308?

how to redirect http to https using a kubernetes ingress controller on Amazon EKS

Helm chart nginx-ingress controller TCP redirect http to https

Serving HTTP/HTTPS service which is outside of Kubernetes cluster through Ingress

Access service via custom HTTPS port using nginx-ingress

Kubernetes 1.16 Nginx Ingress (0.26.1) TCP Mariadb/MySQL service not working

kubernetes nginx ingress controller rewrites

Kibana with nginx ingress controller in Kubernetes

Kubernetes Nginx Ingress Controller on NodePort

Kubernetes http requests from frontend to backend service

Difference between nginx ingress controller kind:service vs kind: Ingress vs kind: configMap in Kubernetes

Migrating an external Kubernetes service from load balancer to ingress controller

Kubernetes Nginx Ingress Controller expose Nginx Webserver

nginx http to https redirection issue

Kubernetes Ingress not working: default backend 404

Kubernetes ingress is not working , default backend 404

Problem Sub Path Ingress Controller for Backend Service

ALB Ingress - Redirect Traffic from HTTP to HTTPS not working

Kubernetes Nginx Ingress can connect to https pods?

My redirect from http to https in Nginx not working

kubernetes nginx ingress controller / caching static assets

TOP Ranking

HotTag

Archive