Skip to content

Name-based Virtual Hosting

Name-based virtual hosting is a networking configuration that allows multiple services (such as websites) to share a single IP address. The system determines which service to route traffic to by inspecting the Host header (hostname) included in the HTTP request^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md].

In the context of Kubernetes Ingress, this is achieved by defining rules that map specific hostnames to specific backend Services.^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md] For example, requests for foo.com can be routed to a "foo" service, while requests for bar.com are routed to a "bar" service, even though both arrive at the same Ingress Controller IP^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md].

This method is often contrasted with path-based routing, where traffic is split based on the URL path, whereas name-based routing splits traffic based on the requested domain.^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md] It is frequently referred to simply as "Virtual hosting" in Kubernetes Ingress configurations^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md].

Configuration

To implement name-based virtual hosting, an Ingress resource typically contains a list of rules. Each rule specifies a host value and a backend service to handle that traffic^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md].

Local Testing

When testing name-based virtual hosting locally (e.g., via localhost), specific hostnames like foo.com do not automatically resolve to the local machine. To function correctly, the local /etc/hosts file must be modified to map the desired hostnames to 127.0.0.1^[400-devops-06-kubernetes-k8s-ithelp-day9-readme.md].

Sources

  • 400-devops-06-kubernetes-k8s-ithelp-day9-readme.md