How to schedule a Pod manually

Eduardo Patrocinio
3 min readJul 8, 2019

Introduction

The goal of Kubernetes is to distribute the Pods across all the nodes, without you worrying about where your Pod will be placed.

Certainly, you can use nodeSelector to determine which nodes will be used, or you can use taint (and toleration) to prevent a certain Pod to be deployed to a certain node.

But do you know you can explicitly tell Kubernetes to schedule a Pod in a certain node?

In this blog, I will show you how to do that. But first…

Why should I schedule a Pod manually?

That’s an interesting question…

The only reasonable scenario I can see is if there is no kube-scheduler Pod available. In this case, we have a chicken-and-egg problem: we can’t deploy a new kube-scheduler Pod, because there is no scheduler available.

How to schedule a Pod manually

So let’s say that your environment has 3 masters and 3 workers, as shown in the picture below:

Now, let’s deploy a normal busybox Pod, using this simple YAML file:

apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']

When we deploy this Pod, Kubernetes will basically choose a worker and deploy there:

patro:v3 edu$ kubectl apply -f busybox.yaml
pod/myapp-pod created

If you look at the Pod information, we see it has been deployed to ip-10–0–165–186.us-east-2.compute.internal:

Cool. Now, let’s look at how we can tell Kubernetes to deploy this Pod a specific node, for example ip-10–0–139–120.us-east-2.compute.internal

To do that, we need to use a special field in the Pod declaration: nodeName. So, here is the new specification:

apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
nodeName: ip-10-0-139-120.us-east-2.compute.internal

containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']

Let’s delete the Pod and recreate it:

patro:v3 edu$ kubectl delete pod myapp-pod
pod “myapp-pod” deleted
patro:v3 edu$ kubectl apply -f busybox.yaml
pod/myapp-pod created

If we now look at the Pod properties, we see:

Awesome! So by specifying the field nodeName, we can direct Kubernetes where to deploy the Pod, bypassing the kube-scheduler

Conclusion

In this blog, I showed how to deploy a Pod manually, using the Pod field nodeName. This scenario is useful in situations when the kube-scheduler Pod is not available.

Bring your plan to the IBM Garage.
Are you ready to learn more about working with the IBM Garage? We’re here to help. Contact us today to schedule time to speak with a Garage expert about your next big idea. Learn about our IBM Garage Method, the design, development and startup communities we work in, and the deep expertise and capabilities we bring to the table.

Schedule a no-charge visit with the IBM Garage.

--

--

Eduardo Patrocinio

Principal Solutions Architect, Strategic Accounts, AWS