Difference between kunernetes Service and Ingress

1/4/2020

I want to create a load balancer for 4 http server pods.

I have one mysql pod too.

Everything works fine, i have created a loadbalancer service for http, and another service for mysql.

I have read i should create an ingress too. But i do not understand what is an ingress because everything works with Services.

What is the value-add of an Ingress ?

Thanks

-- Bob5421
kubernetes

2 Answers

1/4/2020

Since you have single service serving http, your current solution using LoadBalancer service type works fine. Imagine you have multiple http based services that you want to make externally available on different routes. You would have to create a LoadBalancer services for each of them and by default you would get a different IP address for each of them. Instead you can use an Ingress, which sits infront of these services and does the routing.

Example ingress manifest:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /cart
        backend:
          serviceName: cart
          servicePort: 80
     - path: /payment
        backend:
          serviceName: payment
          servicePort: 80

Here you have two different HTTP services exposed by an Ingress on a single IP address. You don't need a LoadBalancer per service when using an Ingress.

-- Shashank V
Source: StackOverflow

1/4/2020

The Service of type LoadBalancer relies on a third-party LoadBalancer and IP provisioning thing somewhere that deals with getting Layer 3 traffic (IP) from outside to the Nodes on some high-numbered NodePort.

A Ingress relies on a third-party Ingress Controller to accept Layer 3 traffic, open it up to Layer 7 (eg, terminate TLS) and do protocol-specific routing (eg by http fqdn/path) to some other Service (probably of type ClusterIP) inside the cluster.

If all your service should be explictly exposed without any further filtering or other options, a LoadBalancer and no Ingress might be the right choice....but LoadBalancers dont do much on their own....they just expose the Service to the outside world....very little in the way of traffic shpaing, A/B testing, etc

However, if you want to put multiple services behind a single IP/VIP/certificate, or you want to direct traffic in some weird ways (like based on Header:, client type, percentage weighting, etc), you'd probably want an Ingress (which itself would be exposed by a LoadBalancer Service)

-- Arghya Sadhu
Source: StackOverflow