<p>According to this doc (<a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-alias" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-alias</a>), I'm able to add additional server_name to the nginx config file.
However, it adds the extra server_name to all of my hosts, which cause conflicts for sure.
Is there a way to add server-alias only for one of my hosts? Say I only want to add 10.10.0.100 to my test1 host.
Ingress example:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/server-alias: 10.10.0.100
spec:
  rules:
  - host: test1.com
    http:
      paths:
      - path: /
        backend:
          service:
            name: test1-service
            port:
              number: 8000
        pathType: Prefix
  - host: test2.com
    http:
      paths:
      - path: /
        backend:
          service:
            name: test2-service
            port:
              number: 8000
        pathType: Prefix

</code></pre>

<p><strong>TL;DR</strong></p>
<p><strong>You can split your <code>Ingress</code> resource on multiple objects (which will work together) to add <code>Annotations</code> to only specific <code>hosts</code>.</strong></p>
<blockquote>
<p><strong><code>Annotations</code> can only be set on the whole kubernetes resource</strong>, as they are part of the resource <code>metadata</code>. The <code>ingress spec</code> doesn't include that functionality at a lower level.</p>
<p>-- <em><a href="https://stackoverflow.com/questions/60749036/apply-nginx-ingress-annotations-at-path-level">Stackoverflow.com: Questions: Apply nginx-ingress annotations at path level</a></em></p>
</blockquote>
<hr />
<p>Extending on the answer to give an example of how such setup could be created. Let's assume (example):</p>
<ul>
<li>All required domains pointing to the <code>Service</code> of type <code>LoadBalancer</code> of <code>nginx-ingress-controller</code>:
<ul>
<li><code>hello.kubernetes.docker.internal</code> - used in <code>host</code> <code>.spec</code></li>
<li><code>hello-two.kubernetes.docker.internal</code> - used in <code>annotations</code> <code>.metadata</code></li>
<li>--</li>
<li><code>goodbye.kubernetes.docker.internal</code> - used in <code>host</code> <code>.spec</code></li>
<li><code>goodbye-two.kubernetes.docker.internal</code>- used in <code>annotations</code> <code>.metadata</code></li>
</ul>
</li>
</ul>
<p>Skipping the <code>Deployment</code> and <code>Service</code> definitions, the <code>Ingress</code> resources should look like below:</p>
<p><code>hello-ingress.yaml</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-ingress
  annotations:
    nginx.ingress.kubernetes.io/server-alias: &quot;hello-two.kubernetes.docker.internal&quot;
spec:
  rules:
  - host: hello.kubernetes.docker.internal # &lt;-- IMPORTANT  
    http:
      paths:
      - path: /
        backend:
          service:
            name: hello-service
            port:
              number: 80
        pathType: Prefix
</code></pre>
<p><code>goodbye-ingress.yaml</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: goodbye-ingress
  annotations:
    nginx.ingress.kubernetes.io/server-alias: &quot;goodbye-two.kubernetes.docker.internal&quot;
spec:
  rules:
  - host: goodbye.kubernetes.docker.internal # &lt;-- IMPORTANT 
    http:
      paths:
      - path: /
        backend:
          service:
            name: goodbye-service
            port:
              number: 80
        pathType: Prefix
</code></pre>
<p>Above definitions will create 2 <code>Ingress</code> resources that will be merged:</p>
<ul>
<li><code>hello-service</code> will respond for:
<ul>
<li><code>hello.kubernetes.docker.internal</code></li>
<li><code>hello-two.kubernetes.docker.internal</code></li>
</ul>
</li>
<li><code>goodbye-service</code> will respond for:
<ul>
<li><code>goodbye.kubernetes.docker.internal</code></li>
<li><code>goodbye-two.kubernetes.docker.internal</code></li>
</ul>
</li>
</ul>
<p>Running:</p>
<ul>
<li><code>$ kubectl get ingress</code>:</li>
</ul>
<pre class="lang-sh prettyprint-override"><code>NAME              CLASS    HOSTS                                ADDRESS     PORTS   AGE
goodbye-ingress   &lt;none&gt;   goodbye.kubernetes.docker.internal   localhost   80      36m
hello-ingress     &lt;none&gt;   hello.kubernetes.docker.internal     localhost   80      36m
</code></pre>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Services networking: Ingress</a></em></li>
<li><em><a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-alias" rel="nofollow noreferrer">Kubernetes.github.io: Ingress NGINX: Annotations: Server alias</a></em></li>
</ul>
