<p>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.</p>

<p>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 <code>run</code> function(present in <code>pkg/kubectl/cmd/newCommand.go</code>) . I guess I can kill and restart pod using a mechanism similar to that used by <code>kubectl delete</code> and <code>create</code> but I am unable to get all the required pod and node lists.</p>

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

<p>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.</p>

<p>Firstly, please see <a href="https://github.com/kubernetes/kubernetes/issues/11793#issuecomment-150410114" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/11793#issuecomment-150410114</a> if you haven't already.</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>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]. </p>

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

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

<blockquote>
  <p>kubectl get pods -o wide --v=7</p>
</blockquote>

<p>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 <em>just</em> want to create/delete, because there's a high chance the scheduler will put the pod on the same node.      </p>

<p>[1] <a href="https://stackoverflow.com/questions/33167023/kubernetes-go-client-used-storage-of-nodes-and-cluster/33177703#33177703">kubernetes go client used storage of nodes and cluster</a><br>
[2] <a href="https://github.com/kubernetes/kubernetes/tree/master/pkg/controller" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/tree/master/pkg/controller</a><br>
[3] <a href="https://github.com/kubernetes/contrib/tree/master/Ingress/controllers" rel="nofollow noreferrer">https://github.com/kubernetes/contrib/tree/master/Ingress/controllers</a></p>
