I am trying to assign clusterIP to a Service in the kube cluster. I know the IP range, so that I can form new IPs from that IP range.
I am implementing proxy within containers. So I need to know the clusterIP of the depending services, so that I can do a proxy from the source container. For this purpose I am specifying the clusterIP at the time of creating a service.
Now the challenge is that I should allocate an IP that is not used by any other service within that cluster, else it will fail.
What I did is the following. I got the list of Services and their IPs in that kube cluster and formed a new IP and made sure that the new IP is not in the pool of IPs already in use and then allocated it to the new service. It works fine in most of the cases.
Now I am facing a strange issue here.
In some cases it fails saying that "Service 'mongodb-4-xmxrv-svc' is invalid: spec.clusterIP: Invalid value: '10.7.240.2': provided IP is already allocated".
But that IP is not used by any of the Services within that kube cluster. I am not sure where that IP is used. Can someone help me out to list the IPs that are used within that kube cluster, so that I can form a new IP and allocate it to the Service?
You can look at all services in all namespaces using:
kubectl get services --all-namespaces
It's likely that a service in the kube-system
namespace has the 10.7.240.2 address.