Compare the Service Types: ClusterIP, NodePort, and LoadBalancer, and when do you use each of them?
ClusterIP is the default type that assigns an internal IP address to a service that is exclusively available within the cluster. NodePort opens a fixed port (in the range 30000-32767) on each node's external IP address to route requests to the internal ClusterIP. LoadBalancer relies on the cloud provider to create an external physical load balancer that automatically routes traffic to the NodePort and from there to the pods.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
The hierarchical levels of service types in Kubernetes are built cumulatively:
- ClusterIP:
- Provides a stable virtual IP address within the cluster’s private network.
- It cannot be accessed from outside the cluster without an intermediary such as Ingress Controller or
kubectl port-forward.
- NodePort:
- Built on top of ClusterIP; Allocates a random or specific port (between 30000 and 32767) on all nodes.
- If you request
<Node-IP>:<NodePort>, Kube-Proxy receives the request and forwards it to the pods even if the pod is on another node.
- LoadBalancer:
- Built on top of NodePort and ClusterIP; Sends a call to the Cloud Controller Manager (such as AWS NLB or GCP Cloud Load Balancing) to reserve a dedicated external public IP address.
- Expose sensitive databases via NodePort or LoadBalancer instead of keeping them behind a secure internal ClusterIP.
- The belief that a Service is a proxy server or an intermediary container; a Service is just an abstract object that is translated into routing rules in iptables or IPVS on each node.
- What is the Headless Service (which has clusterIP: None) and what is its main purpose?
- How does setting ExternalTrafficPolicy: Local affect maintaining the client's real IP address?
What is the difference in performance and architecture between iptables mode and IPVS mode in Kube-Proxy within large clusters?
iptables mode is based on a linear sequential scan (O(N)); as the number of services and pods grows into the thousands, the rule table grows, causing high memory consumption and significant delay in updating packets. While IPVS uses hash tables with constant time complexity (O(1)), and supports advanced load balancing algorithms such as Round-Robin and Least Connection, making it the standard choice for large environments.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Comparison between the two situations:
+--------------------+---------------------------------------+---------------------------------------+
| Property | iptables | IPVS |
+--------------------+---------------------------------------+---------------------------------------+
| Routing complexity O(N) Linear | O(1) constant |
| Performance at +5000 svc| Noticeable degradation and slow sync | Super stability and speed
| Distribution algorithm | Random Prob | rr, lc, wrr, sed, ... |
| Data structure | Chains | Hash Tables are very fast
+--------------------+---------------------------------------+---------------------------------------+In large clusters (with tens of thousands of Endpoints), updating a single rule in iptables can take several seconds and freeze packet processing, while IPVS updates Hash Map elements instantaneously in less than a millisecond.
- The belief is that Kube-Proxy passes network packets by itself as a true proxy in iptables/IPVS mode; in these two modes, Kube-Proxy programs routing rules in kernel space only and packets do not pass through user space.
- Enable IPVS mode without loading pre-required kernel modules such as ip_vs and ip_vs_rr on the nodes.
- What is the role of eBPF and projects like Cilium in completely eliminating Kube-Proxy and iptables?
- How does IPVS handle Connection Tracking & Health Checks?
How does CoreDNS work within Kubernetes, and what is the full structure of a Fully Qualified Domain Name (FQDN) for a service?
CoreDNS automatically resolves service names to ClusterIP addresses. The full form of the FQDN is: <service-name>.<namespace>.svc.cluster.local. In pods within the same Namespace, just the service name is sufficient; if in another Namespace, <service>.<namespace>.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Installation of the official domain of the service:
my-service.production.svc.cluster.local
│ │ │ └── Cluster Domain
│ │ └────── Object type (Service)
│ └───────────────── Namespace
Service NameInside the application capsule, /etc/resolv.conf contains:
nameserver 10.96.0.10
search production.svc.cluster.local svc.cluster.local cluster.local
options windows:5Because of ndots:5, if a container tries to call api.stripe.com (which has only 2 dots, less than 5 dots), the system searches the search suffixes first:
api.stripe.com.production.svc.cluster.local(NXDOMAIN failed)api.stripe.com.svc.cluster.local(NXDOMAIN failed)api.stripe.com.cluster.local(NXDOMAIN failed)- Finally
api.stripe.com(success).
NodeLocal DNSCache reduces this overhead by installing a local DNS cache on each server.
- Sending repetitive external DNS queries without activating NodeLocal DNSCache, causing pressure and bottlenecks in the CoreDNS central network.
- ndots:5 issue in /etc/resolv.conf file that causes up to 4 failed local DNS queries to be sent before any external domain such as google.com is attempted to resolve.
- What is the contents of the default /etc/resolv.conf file inside a pod in Kubernetes?
- How to resolve the DNS address of a specific StatefulSet pod via Headless Service?