Home > Net >  Ingress Routing to different k8s service for sub domains
Ingress Routing to different k8s service for sub domains

Time:07-20

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.

CodePudding user response:

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.

  • Related