Can you schedule a pod on a specific node using `kubectl run`?

Viewed 2000

I have a command kubectl run -it my-pod --image=<my-image> /bin/sh and I'd like the pod to be scheduled on a specific node.

Is that possible and, if so, how?

1 Answers

Get the hostname:

kubectl get nodes

Schedule pod on a specific node:

kubectl run mypod --image ubuntu:18.04 --overrides='{"apiVersion": "v1", "spec": {"nodeSelector": { "kubernetes.io/hostname": "my-node.internal" }}}' --command -- sleep 100000000000000

or

kubectl run mypod --image ubuntu:18.04 --overrides='{"apiVersion": "apps/v1", "spec": {"nodeSelector": { "kubernetes.io/hostname": "my-node.internal" }}}' --command -- sleep 100000000000000

You may need to change apiVersion value, please find one:

kubectl api-versions
Related