In Kubernetes, a Service is used to provide network access to a set of pods, allowing them to communicate with each other and with the outside world. A Service can be exposed using various types, such as ClusterIP, NodePort, and LoadBalancer.
However, when you want to expose multiple services to the outside world using a single IP address, you can use a Kubernetes Ingress. An Ingress is a Kubernetes resource that acts as a layer 7 load balancer, providing routing and TLS termination for HTTP and HTTPS traffic.
An Ingress resource defines rules for how incoming traffic should be directed to backend Services based on the incoming host, path, and other information in the request. The rules can be configured to send traffic to different Services based on the incoming URL, host, or other factors.
For example, the following Ingress resource directs incoming traffic to different Services based on the incoming URL:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /app1
pathType: Prefix
backend:
service:
name: app1-service
port:
number: 80
- path: /app2
pathType: Prefix
backend:
service:
name: app2-service
port:
number: 80
In this example, incoming traffic to example.com/app1 will be directed to the app1-service Service, and incoming traffic to example.com/app2 will be directed to the app2-service Service.
In contrast to a Service, which only provides network access to a set of pods, an Ingress provides a higher level of network functionality, allowing you to route traffic based on incoming host and URL information. This makes it easier to expose multiple services using a single IP address and to manage traffic routing and load balancing for multiple services.
In conclusion, a Kubernetes Ingress is a layer 7 load balancer that provides routing and TLS termination for HTTP and HTTPS traffic, allowing you to expose multiple services using a single IP address and to manage traffic routing and load balancing for multiple services based on incoming host and URL information.