Search code examples
kuberneteskubernetes-ingress

'host' field in Kubernetes Ingress


I am pretty novice in Kubernetes.

From the Kubernetes website, on 'host' field in ingress:

An optional host. In this example, no host is specified, so the rule applies to all inbound HTTP traffic through the IP address specified. If a host is provided (for example, foo.bar.com), the rules apply to that host.

So if I have host as 'x.y.z', path as '/my-service', then only a call like 'x.y.z/my-service/....' would be directed to the configured backend service.

If host is not set, then any call with /my-service in its url would be send to configured backend.

x.y.z/my-service/..

a.b.c/my-service/..

Both would be directed to backend.

Is my understanding correct?


Solution

  • Generally speaking, your understanding is correct.

    Host is a optional parameter that indicates to use a certain host. The usage of the host argument is also related to the DNS management of that address, so in order to use it you also need to either:

    • add the hostname into the DNS record
    • edit the /etc/hosts file (if you're running your environment locally) with the association ip hostname

    After you set this up, you match any path that starts with http://host/path, e.g. http://host/path/1, http://host/path/2.

    You don't match any path that either modify the host or the path prefix.