Kubernetes: Update IPs of pods in a custom loadbalancer after scaling

10/27/2016

I am using a custom loadbalancer for an UDP application that reads the target IPs from a SQL database.

What is the best way to get the ip of the pods after scaling and insert it into the database used by the loadbalancer.

One way I can think of is to use kubectl command to get the pod IPs and insert into DB but with this approach I'll need to keep track of the already inserted IPs and filter those from the command output.

Below is the sample command I'll use to get the ip of the pods:

.\kubectl.exe get pods --selector=app=nginx-test -o=custom-columns=IP:.status.podIP

Is there another way or better way to do this?

Thanks

-- Jardanian
kubectl
kubernetes

1 Answer

11/8/2016

You could create a watch on the pods endpoint in the API, when the pods change it will return that information back to you if it was a new pod or a deleted pod. See the Swagger spec: http://kubernetes.io/kubernetes/third_party/swagger-ui/#!/api%2Fv1/watchNamespacedPodList

Then you would just need to write the code to handle updating your database.

-- Steve Sloka
Source: StackOverflow