Can we use configmaps to dynamically inject a loadbalancerip to a kubernetes service?

apiVersion: v1

kind: Service
metadata:
name: example-service
spec:
selector:
app: example
ports:
- port: 8765
targetPort: 9376
externalTrafficPolicy: Local
type: LoadBalancer
loadBalancerIP: 123.123.123.123

so in the above example this is creating a a service that will create a loadbalancer with a specific public ip that we designate. Is there a way to inject that with a configmap / kube secret?
any other best practices?

Hi Harry,

I don’t think there’s a good way to do what you’re describing, but luckily, Kubernetes already provides a better way of getting the same end result.

If you’re using the DNS extension (we haven’t seen a cluster that doesn’t), then your service IPs are already exposed as DNS entries. That means any Pod in your cluster can connect to http://example-service:8765 and reach the Pods behind that service via the LoadBalancer.

Hope that helps!

Tammersaleh,

Thanks for the quick response and info, that would totally help me address those internal request to those pods behind the service.
However, this loadBalancerIP would be an external IP that I’m trying to bind the service to for external requests. So ideally the service config would be tethered to some configmap or kubesecret.
back to the drawing board I suppose.

Oh, sorry, I misunderstood!

I thought you wanted to grab the IP from the service and create a ConfigMap using that value so you could inject it into a Pod.

Instead, sounds like you have a static IP, and you don’t want to manually add it to the Service configuration - rather, you’d like to have the Service grab the IP from the ConfigMap.

Unfortunately, I don’t know a way of doing that (though GKE provides a similar feature for their Ingress controller using annotations).