Chetan_Tiwary_
Moderator
Moderator
  • 1,622 Views

ClusterIP vs NodePort vs LoadBalancer vs Ingress

As per the official documentation :

In Kubernetes, a Service is a method for exposing a network application that is running as one or more Pods  in your cluster. It is an abstraction to help you expose groups of Pods over a network. Each Service object defines a logical set of endpoints (usually these endpoints are Pods) along with a policy about how to make those pods accessible.

The SERVICE object provides a stable IP address for the CLIENT container on NODE X to send a request to any one of the API containers.

Kubernetes uses labels on the pods to select the pods that are associated with a service. To include a pod in a service, the pod labels must include each of the selector fields of the service.

Chetan_Tiwary__0-1690743836972.png

 

ClusterIP : 

It is the default service type, You can only access this service while inside the cluster. NO external access ( unless you are using a proxy ).

 

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP
  selector:
    tier: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

 

selector is used to select the pods who has a label "tier=backend"

Service listens on port 80/TCP and forwards the requests to the back-end pod on port 8080.

 

Chetan_Tiwary__2-1690745183685.png

 

*********************************************************************************************************************

NodePort:

With this method, Kubernetes exposes a service on a port on the node IP address. The port is exposed on all cluster nodes, and each node redirects traffic to the endpoints (pods) of the service.

 

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    tier: backend
  ports:      
    - port: 80
      targetPort: 80
      nodePort: 30007

 

Port --> Port of the service

targetPort --> Port open on the Pod

NodePort --> port open on the node ( Range 30000-32767)

Chetan_Tiwary__4-1690746297092.png

 

*****************************************************************************************************************

LoadBalancer :

On cloud providers which support external load balancers, setting the type field to LoadBalancer provisions a load balancer for your Service:

 

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    tier: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  clusterIP: 10.0.171.239
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 192.0.2.127

 

 

Chetan_Tiwary__0-1690747227333.png

*******************************************************************************************************************

Ingress: not a service type but a rule to chart external access to services 

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.

An Ingress may be configured to give Services externally-reachable URLs, load balance traffic, terminate SSL / TLS, and offer name-based virtual hosting.

 

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 80

 

This Ingress resource configures the Nginx Ingress Controller (nginx.ingress.kubernetes.io) to handle traffic with the nginx-example class. It routes HTTP requests with a path starting with /testpath to the "my-service" service on port 80 within the Kubernetes cluster.

 

Chetan_Tiwary__2-1690747733163.png

##########################END#############################################

 

Refer : https://kubernetes.io/docs/concepts/services-networking/ 

 

 

0 Replies
Join the discussion
You must log in to join this conversation.