Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Creating and Scheduling a Pod Manually

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.

Create a Pod

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

Scheduling a Pod

Examine Cluster Nodes

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.

Bind a Pod to a Node

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

This comment has been minimized.

Copy link

commented Feb 6, 2019

Sorry for the low-level question, but why don't we simply set pod.spec.nodeName to the desired node? What does the Binding object add?

According to pkg/registry/core/pod/storage/storage.go, the apiserver appears to simply take the value from the Binding object and copy it to pod.spec.nodeName (after performing some checks) - is the Binding object simply there to ensure the checks get performed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.