According to this doc (https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-alias), 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:
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
TL;DR
You can split your
Ingressresource on multiple objects (which will work together) to addAnnotationsto only specifichosts.Extending on the answer to give an example of how such setup could be created. Let's assume (example):
Serviceof typeLoadBalancerofnginx-ingress-controller:hello.kubernetes.docker.internal- used inhost.spechello-two.kubernetes.docker.internal- used inannotations.metadatagoodbye.kubernetes.docker.internal- used inhost.specgoodbye-two.kubernetes.docker.internal- used inannotations.metadataSkipping the
DeploymentandServicedefinitions, theIngressresources should look like below:hello-ingress.yamlgoodbye-ingress.yamlAbove definitions will create 2
Ingressresources that will be merged:hello-servicewill respond for:hello.kubernetes.docker.internalhello-two.kubernetes.docker.internalgoodbye-servicewill respond for:goodbye.kubernetes.docker.internalgoodbye-two.kubernetes.docker.internalRunning:
$ kubectl get ingress:Additional resources: