<p>Suppose I create multiple ingress objects in k8s which point to the same service, same path and are exactly the same, only they have different names eg-. <em>ingress-1</em> and <em>ingress-2</em>. How are the requests handled in this case? Are the requests duplicated or either ingress handles the request?</p>

<p>PS;- I know this doesn't make much sense but I am testing something out.</p>

Divyaanand Sinha
<p>Let's check how it works!</p>
<p>I have default nginx deployment</p>
<pre><code># kubectl -n test get pods -o wide | grep nginx
nginx-65f88748fd-6w6fj           1/1     Running   0          26h     10.8.253.25    k8s-vm02   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-8fp7p           1/1     Running   0          26h     10.8.252.205   k8s-vm01   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-c7j29           1/1     Running   0          26h     10.8.253.24    k8s-vm02   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-frsbq           1/1     Running   0          26h     10.8.252.201   k8s-vm01   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-p4zvm           1/1     Running   0          26h     10.8.252.204   k8s-vm01   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-pd8gv           1/1     Running   0          25h     10.8.253.27    k8s-vm02   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-rkcjl           1/1     Running   0          26h     10.8.252.206   k8s-vm01   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-rn49k           1/1     Running   0          26h     10.8.253.26    k8s-vm02   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-w9dz8           1/1     Running   0          26h     10.8.252.203   k8s-vm01   &lt;none&gt;           &lt;none&gt;
nginx-65f88748fd-xh42v           1/1     Running   0          25h     10.8.253.28    k8s-vm02   &lt;none&gt;           &lt;none&gt;
</code></pre>
<p>service</p>
<pre><code># kubectl -n test get svc
NAME    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
nginx   ClusterIP   10.8.254.218   &lt;none&gt;        80/TCP    12d
</code></pre>
<p>and 2 similar Ingress resources in the same namespace</p>
<pre><code># kubectl -n test get ing
NAME             HOSTS            ADDRESS   PORTS   AGE
test-ingress-1   nginx.test.com             80      20m
test-ingress-2   nginx.test.com             80      20m
</code></pre>
<p>Their YAML's:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: test
  name: test-ingress-1
  annotations:
    kubernetes.io/ingress.class: &quot;service&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: nginx.test.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: nginx
          servicePort: 80
</code></pre>
<p>and</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: test
  name: test-ingress-2
  annotations:
    kubernetes.io/ingress.class: &quot;service&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: nginx.test.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: nginx
          servicePort: 80
</code></pre>
<blockquote>
<p>one more thing about <strong>ingress.class: &quot;service&quot;</strong> - there are more then 1 ingress controllers in my environment and this particular ingress-controller</p>
</blockquote>
<pre><code>nginx-ingress-service-6gkhh                1/1     Running   0          4m20s   10.8.255.243   k8s-vm02   &lt;none&gt;           &lt;none&gt;
</code></pre>
<blockquote>
<p>has been created specially for demonstrating this example, so pay no
attention for it</p>
</blockquote>
<p>Anyway, is Ingress resource <code>nginx.test.com/foo</code> working now?</p>
<pre><code># curl -H &quot;Host: nginx.test.com&quot; http://10.8.255.243:80/foo
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
&lt;style&gt;
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Welcome to nginx!&lt;/h1&gt;
&lt;p&gt;If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.&lt;/p&gt;

&lt;p&gt;For online documentation and support please refer to
&lt;a href=&quot;http://nginx.org/&quot;&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;
Commercial support is available at
&lt;a href=&quot;http://nginx.com/&quot;&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Yes, it is. What's under the hood? Nginx config inside ingress-controller has only one <code>server_name nginx.test.com</code> no matter how many similar Ingress resources we have</p>
<pre><code># kubectl -n kube-system exec nginx-ingress-service-6gkhh -- cat /etc/nginx/nginx.conf
...
## start server nginx.test.com
    server {
        server_name nginx.test.com ;

        listen 80;

        listen [::]:80;

        set $proxy_upstream_name &quot;-&quot;;

        location ~* ^/foo\/?(?&lt;baseuri&gt;.*) {
...
            proxy_pass http://test-nginx-80;
...
    ## end server nginx.test.com

</code></pre>
<p>upstreams:</p>
<pre><code>    upstream test-nginx-80 {

        keepalive 32;

        server 10.8.252.203:80 max_fails=0 fail_timeout=0;
        server 10.8.253.26:80 max_fails=0 fail_timeout=0;
        server 10.8.252.201:80 max_fails=0 fail_timeout=0;
        server 10.8.253.25:80 max_fails=0 fail_timeout=0;
        server 10.8.252.204:80 max_fails=0 fail_timeout=0;
        server 10.8.253.24:80 max_fails=0 fail_timeout=0;
        server 10.8.252.205:80 max_fails=0 fail_timeout=0;
        server 10.8.252.206:80 max_fails=0 fail_timeout=0;
        server 10.8.253.27:80 max_fails=0 fail_timeout=0;
        server 10.8.253.28:80 max_fails=0 fail_timeout=0;

    }
</code></pre>
<p>Let's delete the <code>test-ingress-1</code> Ingress resource</p>
<pre><code># kubectl -n test delete ing test-ingress-1
ingress.extensions &quot;test-ingress-1&quot; deleted
</code></pre>
<p>Ingress is still working:</p>
<pre><code># curl -H &quot;Host: nginx.test.com&quot; http://10.8.255.243:80/foo
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
&lt;style&gt;
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Welcome to nginx!&lt;/h1&gt;
&lt;p&gt;If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.&lt;/p&gt;

&lt;p&gt;For online documentation and support please refer to
&lt;a href=&quot;http://nginx.org/&quot;&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;
Commercial support is available at
&lt;a href=&quot;http://nginx.com/&quot;&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>So, you can create as many similar Ingress resources as you want (In case of using nginx-ingress-controller)</p>
<p><strong>UPD:</strong>
Let's create one more deployment in the same namespace:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache
  namespace: test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: apache
  template:
    metadata:
      labels:
        app: apache
    spec:
      containers:
      - name: frontend
        image: httpd
        ports:
        - containerPort: 80
</code></pre>
<p>and one more service</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: apache
  namespace: test
spec:
  ports:
  - name: 80-80
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: apache
  type: ClusterIP
</code></pre>
<p>Next let's change Ingress resource <code>test-ingress-2</code>:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: test
  name: test-ingress-2
  annotations:
    kubernetes.io/ingress.class: &quot;service&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: nginx.test.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: apache # &lt;-------
          servicePort: 80
</code></pre>
<p>Finally namespace <code>test</code> includes this list of resources:</p>
<pre><code># kubectl -n test get all
NAME                                 READY   STATUS    RESTARTS   AGE
pod/apache-cfdf8d79c-2m666           1/1     Running   0          13m
pod/apache-cfdf8d79c-d995s           1/1     Running   0          13m
pod/apache-cfdf8d79c-tq8d7           1/1     Running   0          13m
pod/nginx-65f88748fd-6w6fj           1/1     Running   0          45h
pod/nginx-65f88748fd-8fp7p           1/1     Running   0          45h
pod/nginx-65f88748fd-c7j29           1/1     Running   0          45h
pod/nginx-65f88748fd-frsbq           1/1     Running   0          46h
pod/nginx-65f88748fd-p4zvm           1/1     Running   0          45h
pod/nginx-65f88748fd-pd8gv           1/1     Running   0          45h
pod/nginx-65f88748fd-rkcjl           1/1     Running   0          45h
pod/nginx-65f88748fd-rn49k           1/1     Running   0          45h
pod/nginx-65f88748fd-w9dz8           1/1     Running   0          45h
pod/nginx-65f88748fd-xh42v           1/1     Running   0          45h

NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/apache   ClusterIP   10.8.254.47    &lt;none&gt;        80/TCP    12m
service/nginx    ClusterIP   10.8.254.218   &lt;none&gt;        80/TCP    12d

# kubectl -n test get ing
NAME             HOSTS            ADDRESS   PORTS   AGE
test-ingress-1   nginx.test.com             80      9m15s
test-ingress-2   nginx.test.com             80      54s
</code></pre>
<p>the ingreess-controller's <code>nginx.conf</code> shows two lists of upstreams</p>
<pre><code>    upstream test-apache-80 {

        keepalive 32;

        server 10.8.253.31:80 max_fails=0 fail_timeout=0;
        server 10.8.252.208:80 max_fails=0 fail_timeout=0;
        server 10.8.253.32:80 max_fails=0 fail_timeout=0;

    }

    upstream test-nginx-80 {

        keepalive 32;

        server 10.8.252.204:80 max_fails=0 fail_timeout=0;
        server 10.8.252.205:80 max_fails=0 fail_timeout=0;
        server 10.8.253.27:80 max_fails=0 fail_timeout=0;
        server 10.8.253.25:80 max_fails=0 fail_timeout=0;
        server 10.8.253.24:80 max_fails=0 fail_timeout=0;
        server 10.8.252.206:80 max_fails=0 fail_timeout=0;
        server 10.8.253.26:80 max_fails=0 fail_timeout=0;
        server 10.8.252.203:80 max_fails=0 fail_timeout=0;
        server 10.8.253.28:80 max_fails=0 fail_timeout=0;
        server 10.8.252.201:80 max_fails=0 fail_timeout=0;

    }
</code></pre>
<p>but it proxies requests only to one of them</p>
<pre><code>    ## start server nginx.test.com
    server {
        server_name nginx.test.com ;

        listen 80;

        listen [::]:80;

        set $proxy_upstream_name &quot;-&quot;;

        location ~* ^/foo\/?(?&lt;baseuri&gt;.*) {

            set $namespace      &quot;test&quot;;
            set $ingress_name   &quot;test-ingress-1&quot;; &lt;------
            set $service_name   &quot;nginx&quot;;
            set $service_port   &quot;80&quot;;
            set $location_path  &quot;/foo&quot;;

...

            rewrite /foo/(.*) /$1 break;
            rewrite /foo / break;
            proxy_pass http://test-nginx-80;  &lt;-------

            proxy_redirect                          off;
</code></pre>
<pre><code># curl -H &quot;Host: nginx.test.com&quot; http://10.8.255.243:80/foo
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
...
</code></pre>
<p>Each of ingress resources appears there in accordance with the creation time. Deleting Ingress resource</p>
<pre><code>ingress.networking.k8s.io &quot;test-ingress-1&quot; deleted
</code></pre>
<p>makes ingress-controller proxy traffic to Apache upstreams</p>
<pre><code># curl -H &quot;Host: nginx.test.com&quot; http://10.8.255.243:80/foo
&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;
</code></pre>
<p>to make it clear we can recreate Ingress resources in reverse order:</p>
<pre><code># kubectl -n test delete ing test-ingress-1 test-ingress-2
ingress.extensions &quot;test-ingress-1&quot; deleted
ingress.extensions &quot;test-ingress-2&quot; deleted

# kubectl -n test create -f /tmp/ing2.yaml
ingress.networking.k8s.io/test-ingress-2 created # Apache
# kubectl -n test create -f /tmp/ing1.yaml
ingress.networking.k8s.io/test-ingress-1 created # Nginx

# curl -H &quot;Host: nginx.test.com&quot; http://10.8.255.243:80/foo
&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt; # Apache
</code></pre>
<blockquote>
<p>One more note:
There are some cases of reloading the ingress-controller's config, I mean when it reloads config and how it actually reloads config? But that's a totally different question...</p>
</blockquote>
