Gregory Suvalian
Gregory Suvalian

Reputation: 3832

Can I have both http and https in Ingress configuration?

I have ingress yaml like below which makes ingress to proxy HTTPS to HTTP connection. I'm confused how can I make this same ingress to process also HTTP to HTTP connection. Meaning I want it to use the same rule for both incoming HTTP or HTTPS. Removing tls portion makes it work with HTTP but adding it stops HTTP and makes it HTTPS only. Is it limitation of Kubernetes which prevents both HTTP and HTTPS routing in the same ingress controller?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  tls:
    - hosts:
        - "*.mydomain.com"
      secretName: aks-ingress-tls
  rules:
    - host: "*.mydomain.net"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: frontend-service
                port:
                  number: 80

Upvotes: 1

Views: 2932

Answers (1)

congbaoguier
congbaoguier

Reputation: 1045

You should redirect the HTTP request to your HTTPS listener. The requests hitting your Azure LB 80/443 listeners will be handled in the same way.

Due to Azure App gateway limitation, you cannot use a wildcard host in your ingress rules and you have to use workarounds.

See: https://azure.github.io/application-gateway-kubernetes-ingress/annotations/#ssl-redirect

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - "*.mydomain.com"
      secretName: aks-ingress-tls
  rules:
    - host: "www.mydomain.com"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: frontend-service
                port:
                  number: 80

Upvotes: 2

Related Questions