Schedule Kubernetes Pods to Nodes
If your pods have a particular need like a high configuration, take a look at how you are able to configure them to run on specific nodes.
Join the DZone community and get the full member experience.
Join For FreeIn this article, we will see that how to schedule the pod to run in a particular node. You may get a scenario where you want to have more control on a node where a pod runs, such as a pod which may need high resources like heap, storage, cpu core, etc. It can be pointed to higher configuration node in a cluster, which has dependencies that can be executed in a particular node so you may co-locate the pods based on your needs.
I had difficulties in finding the exact steps over to schedule the pod in a node. I hope it will help you. Let's see the detailed technical steps.
Create the label to run the pod in a particular slave/node using node affinity. Using "kubectl get nodes", you can get the available nodes. Choose one of the node and replace with <node-name> as shown below. Excute the below commands in the shell(Linux platform).
Command:
kubectl label nodes <node-name> <label-key>=<label-value>
Example:
kubectl label nodes ip-123-12-123-12 thisnode=slavelabel
You can check the created label using the following command.
kubectl get nodes --show-labels
Example:
kubectl get nodes --show-labels | grep slavelabel
To delete label,
kubectl label nodes <node-name> <label-key>-
Below JSON format works fine. To see the result, kubectl run command with the --overrides
option to run the pod in the particular slave node.
kubectl run -i --tty ubuntu --rm --image=ubuntu --restart=Never --overrides='
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "ubuntutest"
},
"spec": {
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "thisnode",
"operator": "In",
"values": [
"slavelabel"
]
}
]
}
]
}
}
}
}
}
'
To know more about pods assignments, please refer this documentation.
Opinions expressed by DZone contributors are their own.
Comments