This tutorial demonstrates how to create a Pod and manually schedule it to a node using cURL. This guide assumes you don't have a scheduler running in your Kubernetes cluster.
The following pod will run version 1.10.0 of nginx with a 100m CPU limit.
Create the nginx pod manifest and name it pod.json
:
{
"kind":"Pod",
"apiVersion":"v1",
"metadata":{
"name":"nginx",
"labels":{
"run":"nginx"
}
},
"spec":{
"containers":[
{
"name":"nginx",
"image":"nginx:1.10.0",
"resources":{
"requests":{
"cpu":"100m"
}
}
}
],
"imagePullPolicy":"Always"
}
}
Use cURL to create the nginx Pod:
curl -X POST http://127.0.0.1:8080/api/v1/namespaces/default/pods \
-H "Content-Type: application/json" \
-d @pod.json
List all nodes using cURL
curl http://127.0.0.1:8080/api/v1/nodes
Chose one of the nodes from the response. You'll need the node name.
Create binding.json
{
"apiVersion":"v1",
"kind":"Binding",
"metadata": {
"name":"nginx"
},
"target": {
"apiVersion":"v1",
"kind":"Node",
"name":"node1"
}
}
Post the binding to the pod's binding subresource:
curl -X POST http://127.0.0.1:8080/api/v1/namespaces/default/pods/nginx/binding \
-H "Content-Type: application/json" \
-d @binding.json
@adrianludwin According to this article, the scheduler is not allowed to change
pod.spec.nodeName
directly. I guess the Binding object is used to perform the required checks in an organised way, like if the pod is already assigned to a node.