Get internal IP of pod that is being killed in Kubernetes?

2/10/2016

I'm trying to get the internal IP of a pod that is being killed. What I do now is to subscribe to events with reason "Killing" that have an "involvedObject" that is of type "Pod". If so I try to retrieve the pod to get its IP. The problem (I think) is that the Pod is already killed by the time I make the request to get it so I cannot its IP this way (this approach works fine when reason is "Created").

Is there a way to get the internal IP of a pod that is being stopped/killed before it's actually removed by Kubernetes?

Update

What I try to do is to implement a Kubernetes service discovery module (A) for Turbine to detect all of the pods that expose Hystrix streams. I use fabric8 k8s library to watch for Kubernetes events. When an event is discovered by A to be a pod running with label "hystrix-stream" I load the pod details (using the fabric8 library) in order to the get internal IP to the pod. This IP is then sent to Turbine so that it subscribes to the hystrix stream. This works great! The problem is that when A discovers that a pod is being killed I cannot load the pod details since by that time the pod has already been removed. Thus I cannot get the IP of the pod and I cannot tell Turbine to unsubscribe from this pod. My workaround is to maintain state in A that maps the pod name to its IP address. So what I'm after is a way to avoid maintaining this state in A and instead ask Kuberentes for the IP address of a pod that is being killed.

-- Johan
google-kubernetes-engine
kubernetes

1 Answer

2/10/2016

Johan-

You can watch the pods resource to get add/update/remove events for them. http://kubernetes.io/v1.1/docs/api-reference/v1/operations.html, search for 'list or watch objects of kind Pod'. Hope that helps.

Note, events above does not refer to the Event API resource, but rather watch events.

-- Paul Morie
Source: StackOverflow