Manual scheduling with POST method

Hi,

I’m learning Mannambeth’s CKA course in Udemy.
In the lecture [53. Manual Scheduling], he said that we can POST binding to the kube-apiserver for manual scheduling.

Belows are my trails (I tested in KillerCoda environment) :

  1. make an nginx pod with kubectl run nginx --image=nginx. The pod was scheduled on node01
  2. open apiserver by kubectl proxy command
  3. make a binding.json file
cat <<EOF > binding.json
{
   "apiVersion":"v1",
   "kind":"Binding",
   "metadata": {
      "name":"nginx"
   },
   "target": {
      "apiVersion":"v1",
      "kind":"Node",
      "name":"controlplane"
   }
}
EOF
  1. POST the binding.json file to the api server
curl -X POST http://127.0.0.1:8001/api/v1/namespaces/default/pods/nginx/binding \
  -H "Content-Type: application/json" \
  -d @binding.json
  1. result
    {
    “kind”: “Status”,
    “apiVersion”: “v1”,
    “metadata”: {},
    “status”: “Failure”,
    “message”: “Operation cannot be fulfilled on pods/binding "nginx": pod nginx is already assigned to node "node01"”,
    “reason”: “Conflict”,
    “details”: {
    “name”: “nginx”,
    “kind”: “pods/binding”
    },
    “code”: 409
    }

I posted this topic because the result conflicts to the lecture.
Thank you

If I understand what you’re trying to do, the error you’re getting – a code 409 – suggests that you can’t bind pod that has already been scheduled. Try the following and see if it works:

  1. Deactivate the scheduler by removing kube-scheduler.yaml from /etc/kubernetes/manifests; then restart kubelet with systemctl restart kubelet
  2. Create the nginx pod as you did previously; since there is not scheduler, the pod will be in a Pending state.
  3. Apply the binding with curl as you did above. Since the pod is not already scheduled, I think it will work.
1 Like

Your advice exactly worked.

I understand the error situation as
“if the kube-scheduler alive, kube-apiserver prevents POST Binding object manually.”

Is that right?

It does, although, the key thing is that once a pod is scheduled to a node, you can’t schedule it again. Disabling kube-scheduler prevents you from scheduling pods without doing something manually, and doing a POST bind is an action you can take that will manually schedule something.