Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ingress Routing to different k8s service for sub domains

I am trying to create an ingress that routes to service1 when service1.domain.com is entered & service2 when service2.domain.com is entered.
My ingress file looks like this below.
I am on Azure AKS and using Azure App gateway as my ingress controller. Below is how my ingress yaml looks like.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  annotations: 
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
  - host: service1.domain.com
  - http:
      paths:
      - path: /
        backend:
          service:
            name: service1
            port:
              number: 80
        pathType: Prefix      
  - host: service2.domain.com
  - http:
      paths:
      - path: /
        backend:
          service:
            name: service2
            port:
              number: 80
        pathType: Prefix

However, both the domains are getting routed to service2. Can someone help what I am missing here.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The spec look wrong. It should be:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  annotations: 
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
  - host: service1.domain.com
    http:
      paths:
      - path: /
        backend:
          service:
            name: service1
            port:
              number: 80
        pathType: Prefix      
  - host: service2.domain.com
    http:
      paths:
      - path: /
        backend:
          service:
            name: service2
            port:
              number: 80
        pathType: Prefix

There should be two items in your rules, one for each subdomain. http and host are two fields of the same item.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading