The main difference between ClusterIP, NodePort, and LoadBalancer is that you can expose your service with minimal ClusterIP (within the k8s cluster) or larger exposure with NodePort (within the cluster external to the k8s cluster) or LoadBalancer (external world or whatever you defined in your LB).
ClusterIP exposure < NodePort exposure < LoadBalancer exposure
- ClusterIP
Expose service through k8s cluster withip/name:port
- NodePort
Expose service through Internal network VM’s also external to k8sip/name:port
- LoadBalancer
Expose service through the External world or whatever you defined in your LB.
Kubernetes is an orchestration platform for containerized applications. It provides a robust set of features to manage and scale applications across multiple nodes.
One of the core components of Kubernetes is the Service object, which is used to expose applications running in Pods to the network, either within the cluster or externally.
There are three primary types of Services in Kubernetes: ClusterIP, NodePort, and LoadBalancer. Each type serves a specific purpose and has its unique characteristics.
ClusterIP
- Default service type in Kubernetes.
- Exposes the service on an internal IP within the cluster.
- Accessible only from within the cluster.
- Provides a stable IP address and DNS name.
- Ideal for internal communication between services or applications within the cluster.
- Does not expose the service to the external network.
NodePort
- Exposes the service on a static port on each node in the cluster.
- Accessible both from within the cluster and externally, using the Node IP and specified port.
- Port range: 30000-32767 (default, but can be customized).
- Suitable for scenarios where external access is required, and a dedicated LoadBalancer is not available or cost-effective.
- It is not recommended for production environments due to the lack of advanced load balancing and traffic routing features.
LoadBalancer
- Exposes the service externally using a cloud provider’s load balancer.
- Automatically provisions and configures the load balancer to route external traffic to the service.
- Provides advanced load balancing and traffic routing features such as SSL termination, health checks, and session persistence.
- Requires a compatible cloud provider or an external load balancer that supports Kubernetes integration (e.g., MetalLB for on-premises or bare-metal environments).
- Most suitable for production environments that require high availability, scalability, and advanced traffic management features.
That’s it.