Where does the code for K8s services like ClusterIP/NodePort run?

Hello All,

I have been training some people on Kubernetes and have received few questions from some attendees. Personally I have ignored these things as K8s is managing all this. Here are the questions:

  1. Where does the code for services like ClusterIP/NodePort runs? Is it on the worker node/master node?
  2. As per Kubernetes Docs, when you provision a LoadBalancer service, corresponding NodePort service and ClusterIP services are automatically created for you. Surprisingly I am not seeing that happening. I am provisioning a public LoadBalancer on Azure and when I describe this LoadBalancer service using kubectl describe command, I do not see NodePort getting assigned an IP. Its written in the output. Only EndPoint IPs are given. So where exactly is the mapping between LoadBalancer and NodePort services for all the worker nodes?

Cluster information:

Kubernetes version: 1.20.9
Cloud being used: (put bare-metal if not on a public cloud) Azure
Installation method: Azure Kubernetes Cluster using Azure CLI
Host OS: Ubuntu 18.04
CNI and version: Azure CNI v1.4.14
CRI and version: containerd v1.4.9+azure

Thanks,
Himanshu.

Do you mean the code that allocates those? The apiserver. Or do you mean the code that routes traffic for those? Generally the kube-proxy.

I don’t understand the question. All LoadBalancer services also have Nodeports (unless you set AllocatLoadBalancerNodePorts=false) and ClusterIPs. kubectl get -o yaml that Service.

For your first question I mean the code that routes the traffic for these services. So for example ClusterIP routes to different PODs where does this code which is doing the routing run? Node or somewhere else.

For the second let me elaborate again:
I am creating the public LoadBalancer using manifest files as given on kubernetes.io portal. As per this link Publishing Services (ServiceTypes) Section when you create a LoadBalancer service. The NodePort service and ClusterIP Services to which the external load balancer routes are automatically created.

Now when I do kubectl get services -o wide I don’t see the NodePort service which should be mapped to my LoadBalancer service. All I see is the Cluster IP service. Also I when I describe the LoadBalancer service I see NodePort as “unset”.

Please see the image attached.

That lives in kube-proxy or the equivalent replacements thereof.

It doesn’t make more Services - this same Service does all. In your example it shows an IP (clusterIP), a NodePort (the port name is unset), and an LB

1 Like