What happened: The load_balancer_ip label for the kube_service_info metric is always returned empty, regardless of the actual IP assigned to Services of type LoadBalancer (which actually have an IP)
> $ curl -sS localhost:8080/metrics | grep load_balancer_ip | grep management-ingress-nginx-controller
kube_service_info{namespace="ingress-management",service="management-ingress-nginx-controller",cluster_ip="172.x.x.x",external_name="",load_balancer_ip=""} 1
What you expected to happen: load_balancer_ip to either have the proper value or to be removed (see below)
How to reproduce it (as minimally and precisely as possible): Reproduced for kube-state-metrics 1.9.7 and 1.9.8 on Kubernetes 1.19.3, with LoadBalancer Services and Metallb.
Anything else we need to know?:
This value is correctly returned in the ip label of the kube_service_status_load_balancer_ingress metric.
> $ curl -sS localhost:8080/metrics | grep -ie balancer | grep -e 62.x | grep nginx
kube_service_status_load_balancer_ingress{namespace="ingress-management",service="management-ingress-nginx-controller",ip="62.x.x.x",hostname=""} 1
kc -n ingress-management get service management-ingress-nginx-controller
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
management-ingress-nginx-controller LoadBalancer 172.x.x.x 62.x.x.x 80:32518/TCP,443:32075/TCP 78d
kc -n ingress-management get service management-ingress-nginx-controller -o yaml
Environment:
kubectl version):Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:41:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
It is unclear to me whether this is an implementation bug, that is, kube_service_info{load_balancer_ip} should work; or whether I should be using kube_service_status_load_balancer_ingress{ip} instead. Any advice regarding this is greatly appreciated!
As per https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer, you can specify the loadBalancerIP for a service.
kube_service_info uses this value of loadBalancerIP specified in the spec of the service in the load_balancer_ip label. If it is not specified, the value of the label is empty. However kube_service_status_load_balancer_ingress, uses the .status.loadBalancer field for the value of the ip label.
So if you are not specifying the spec.loadBalancerIP field, you can use kube_service_status_load_balancer_ingress{ip}
Many thanks for the explanation @harjas27, this actually makes sense!
Hey sorry, this seems to have gone by our radar, is everything clear or do you need any more info from our side? Thanks @harjas27 for answering!
I think my main question was solved already, but just to clarify, would kube_service_status_load_balancer_ingress{ip} be populated if loadBalancerIP is defined in the service spec? I'm trying to figure out if I need to query both, or just the kube_service_status_load_balancer_ingress{ip} will do the trick :)
Thanks!
@roobre it takes the IP from the Load Balancer Ingress IP https://github.com/kubernetes/kube-state-metrics/blob/eba9142028841d5181ce09836fb1e0c2cf54f90c/internal/store/service.go#L141-L148
So only if you have it defined like https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer it should take that IP yes.
Awesome, thanks for the clarification!