Accessing pod data for rescheduler

11/12/2015

I want to implement a rescheduler like functionality which basically kills pods if it decides that the pods could be rescheduled in a better way (based on requiring less number of nodes/fitting etc). Till now I have created a new kubectl command which I want to run whenever I want to reschedule. I have also looked at the code and rescheduler proposal in the docs.

But, I am unable to access the pod details that would be needed to decide which pod to kill if any from the command's run function(present in pkg/kubectl/cmd/newCommand.go) . I guess I can kill and restart pod using a mechanism similar to that used by kubectl delete and create but I am unable to get all the required pod and node lists.

For example, the objs variable in pkg/kubectl/cmd/get.go (used for kubectl get) contains pod details but there is no data of which node they are scheduled on and what are the resource capacities for that node.

I would be grateful if someone could give some idea of how to get these details. Also, if it is easier to implement it at some other place instead of as a kubectl command then such suggestions are also welcomed.

-- Nishant
kubernetes

1 Answer

11/12/2015

Firstly, please see https://github.com/kubernetes/kubernetes/issues/11793#issuecomment-150410114 if you haven't already.

I guess I can kill and restart pod using a mechanism similar to that used by kubectl delete and create but I am unable to get all the required pod and node lists.

I would suggest writing a control loop instead. When you create a pod it's stored in the master and you can easily create a Kubernetes client to retrieve this pod, in the same way the Kubernetes scheduler does. See [1] for how to access the api through a client. With this in mind, I would suggest writing a control loop. There are several existing examples [2], but a very basic controller is the Ingress controller (just so you aren't confused by all the code in production controllers) [3].

A problem you will face is getting the Kubernetes scheduler to ignore the pod. See discussion on the github issue for solutions.

It is possible to go the route you're on and implement it in kubectl, if you still want to. Run:

kubectl get pods -o wide --v=7

Note this output has node names, and kubectl should show you the REST calls it's making in the process. I suspect you will run into problems soon though, as you really don't just want to create/delete, because there's a high chance the scheduler will put the pod on the same node.

[1] kubernetes go client used storage of nodes and cluster
[2] https://github.com/kubernetes/kubernetes/tree/master/pkg/controller
[3] https://github.com/kubernetes/contrib/tree/master/Ingress/controllers

-- Prashanth B
Source: StackOverflow