The following example would expose the services externally. So why is NodePort
/LB
allowed in this context, would not that be redundant?
rules:
- host: lab.example.com
http:
paths:
- path: /service-root
backend:
serviceName: clusterip-svc
servicePort: 8080
- path: /service-one
backend:
serviceName: nodeport-svc
servicePort: 8080
- path: /service-two
backend:
serviceName: headless-svc
servicePort: 8080
Is there any particular advantage of using NodePort
, ClusterIP
, LoadBalancer
, or Headless
as back-end to Ingress?
So why is NodePort/LB allowed in this context, would not that be redundant?
Mostly no one do it that way, as everyone manages and keeps the ingress as the single point of entry to the cluster. Behind ingress mostly ClusterIP services will be running still it's up to you how you want to set it up.
Is there any particular advantage of using NodePort, ClusterIP, LoadBalancer, or Headless as back-end to Ingress?
i am not aware about any benefit, as each type has its own benefits. ingress will forward the traffic if you will provide service it doesn't check any type or so.
Node port, Loadbalancer can be useful for specific requirements.
Services are a way to define logical set of Pods and a policy to access them. The Pods are ephemeral resources, so Services make it possible to connect to them regardless of their IP addresses. They usually use selectors to do so. There are different types of Services in Kubernetes and these are the main differences.
Cluster IP is a default type of Service. It exposes the Service on a cluster-internal IP and makes it available only from within the cluster.
NodePort exposes the Service on each Node's IP at a static port. This option also creates ClusterIP Service, to which NodePort routes.
LoadBalancer goes a step further and exposes the Service externally using cloud provider's load balancer. NodePort and ClusterIP resources are created automatically.
Follow this link to get more information about different ServiceTypes.
And there are Headless Services. You would use these when you don't need load-balancing and a single Service IP. You can follow this section in documentation for further clarification.
Answering your question - it depends on your use-case, you might find different advantages using these Services.