<p>I have a k8s cluster like below</p>

<pre>
#kubectl get all

NAME                                                 READY   STATUS    RESTARTS   AGE
pod/nginx-ingress-controller-d78c45477-gxm59         1/1     Running   0          8d
pod/nginx-ingress-default-backend-5b967cf596-dc8ss   1/1     Running   0          8d

NAME                                    TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)                      AGE
service/kubernetes                      ClusterIP      10.245.0.1                 443/TCP                      9d
service/nginx-ingress-controller        LoadBalancer   10.245.203.193   A.B.C.D   80:30033/TCP,443:31490/TCP   8d
service/nginx-ingress-default-backend   ClusterIP      10.245.58.229              80/TCP                       8d

NAME                                            READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-ingress-controller        1/1     1            1           8d
deployment.apps/nginx-ingress-default-backend   1/1     1            1           8d

NAME                                                       DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-ingress-controller-d78c45477         1         1         1       8d
replicaset.apps/nginx-ingress-default-backend-5b967cf596   1         1         1       8d
</pre>

<p>As above, I have an external ip A.B.C.D.</p>

<p>I also have two domains domainA.com and domainB.com.</p>

<p>My DNS setting is like below:</p>

<p>for domainA.com:</p>

<pre>
-----domain A----
A www.domainA.com A.B.C.D
-----domain B----
A www.domainB.com A.B.C.D
</pre>

<p>After I install two apps with helm</p>

<p>I got</p>

<pre>
# kubectl describe ingress

Name:             app1
Namespace:        default
Address:          A.B.C.D
Default backend:  default-http-backend:80 ()
Rules:
  Host            Path  Backends
  ----            ----  --------
  www.domainA.com
                     app1:80 (10.244.1.15:80,10.244.1.33:80)

Annotations:
  kubernetes.io/ingress.class:  nginx
Events:
  Type    Reason  Age    From                      Message
  ----    ------  ----   ----                      -------
  Normal  CREATE  10m    nginx-ingress-controller  Ingress default/app1
  Normal  UPDATE  9m48s  nginx-ingress-controller  Ingress default/app1


Name:             app2
Namespace:        default
Address:          A.B.C.D
Default backend:  default-http-backend:80 ()
Rules:
  Host         Path  Backends
  ----         ----  --------
  www.domainB.com
                  app2:80 (10.244.1.15:80,10.244.1.33:80)

Annotations:
  kubernetes.io/ingress.class:  nginx
Events:
  Type    Reason  Age    From                      Message
  ----    ------  ----   ----                      -------
  Normal  CREATE  8m24s  nginx-ingress-controller  Ingress default/app2
  Normal  UPDATE  7m49s  nginx-ingress-controller  Ingress default/app2

</pre>

<p>I don't know why the backends have two IPs.</p>

<p>www.domainA.com and www.domainB.com may route to same ip(10.244.1.15:80) which is I don't want.</p>

<p>I want a single external ip route to different pods by hosts like virtual server</p>

<pre>
www.domainA.com
                     app1:80 (10.244.1.15:800)

-----------------
www.domainB.com
                     app2:80 (10.244.1.33:80)
</pre>

<p>How could I fix my configuration?</p>

<p>Thank you</p>

Min-Yi Tsai
<p>If I understood the situation correctly you would like to have single external IP domains A and B resolved to, single Ingress and two different apps (one per domain). And at the moment the issue is that traffic is delivered to Both Apps instated of proper routing. </p>

<p>Unfortunately, you haven't provided your Ingress and Services configs. That is why I'll have to explain all needed setup :)</p>

<p>What is needed here is to have  2 distinct apps (with different labels), 2 distinct services that route to endpoints for each service and single Ingress that lists both domains.</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: name-virtual-host-ingress
spec:
  rules:
  - host: domain-A
    http:
      paths:
      - backend:
          serviceName: service-A
          servicePort: 8080
  - host: domain-B
    http:
      paths:
      - backend:
          serviceName: Service-B
          servicePort: 8080
</code></pre>

<p>here we've created Ingress that routes traffic for 2 different services</p>

<pre><code>apiVersion: v1
kind: Service
metadata: 
  name: Service-A 
spec: 
  selector: 
    app: nginx
  ...
</code></pre>

<p>I've omitted half of the services specs for clarity. The most important point is  "selector"</p>

<p>It is needed to create 2 services with 2 different selectors. 
You can check services and corresponding EndPoints with the  <code>kubectl get svc -o wide</code> and  <code>kubectl get ep</code></p>

<p>Needless to say, that both apps shall be deployed separately to have different labels.</p>

<p>Please check your config and compare with the above.</p>

<p>Hope that helps. Will be happy to elaborate further if needed.</p>
