AKS Ingress is not routing properly

3/28/2020

I have 2 websites. Each of the site has their corresponding subdomain. To achieve this in AKS, I'm using nginx-ingress to route the traffic according to incoming subdomain.

When I enter http://web1.testing.com/, nginx-ingress is routing me to testing-web1. If I enter http://web2.testing.com/, nginx-ingress will route me to testing-web1 instead of testing-web2.

Is this an expected behavior? Did I miss-configure something? I think I'm almost there, but I couldn't figure out what went wrong.

Thanks.

  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: testing-web1
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: testing-web1
    minReadySeconds: 5 
    template:
      metadata:
        labels:
          app: testing-web1
      spec:
        nodeSelector:
          "beta.kubernetes.io/os": linux
        containers:
        - name: testing-web1
          image: image-web1:1.0
          ports:
          - containerPort: 80
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: testing-web2
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: testing-web2
    minReadySeconds: 5 
    template:
      metadata:
        labels:
          app: testing-web2
      spec:
        nodeSelector:
          "beta.kubernetes.io/os": linux
        containers:
        - name: testing-web2
          image: image-web2:1.0
          ports:
          - containerPort: 80
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: testing-web1
    labels:
      app: testing-web1
  spec:
    ports:
    - port: 80
    selector:
      app: testing-web1
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: testing-web2
    labels:
      app: testing-web2
  spec:
    ports:
    - port: 80
    selector:
      app: testing-web2
  ---
  apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: webapp-ingress
    annotations:
      kubernetes.io/ingress.class: nginx
      certmanager.k8s.io/cluster-issuer: letsencrypt-staging
      nginx.ingress.kubernetes.io/rewrite-target: /
  spec:
    tls:
    - hosts:
      - web1.testing.com
      - web2.testing.com
    rules:
    - host: web1.testing.com
      http:
        paths:
        - path: /
          backend:
            serviceName: testing-web1
            servicePort: 80
    - host: web2.testing.com
      http:
        paths:
        - path: /
          backend:
            serviceName: testing-web2
            servicePort: 80
    - http:
        paths:
        - backend:
            serviceName: testing-web1
            servicePort: 80
          path: /
-- WenHao
azure-kubernetes
kubernetes-ingress
nginx

0 Answers