Nick's Blog

Kubernetes Use nodeSelector to deploy pod into specific node

I had a request from one of my client, his requirement is to run a pod on a specific node. I’ve implement the following by using nodeSelector.

Take a look the following basic operations before get started.

# Show node with specific label
kubectl get nodes --selector=kubernetes.io/hostname=host01

# get pods with all the labels
kubectl get pods --show-labels

# filter the result with label
kubectl get pods --show-labels --selector=type=nginx

Create a Kubernetes label with a tag such as fastssd

kubectl label node aks-nodesproduction-387834275-01 disktype=fastssd

You should able to see aks-nodesproduction-387834275-01 when you select that label

kubectl get nodes --show-labels --selector=disktype=fastssd

Clean up by removing the labels

kubectl label node aks-nodesproduction-387834275-01 disktype-

Create a pod with the label

# pod.yaml
...
spec:
  nodeSelector:
    disktype:fastssd
  containers:
...

Now you should be able to see the pod is running on node-01. Ideally you should avoid to run pod on a specific node. Instead, you should run that pod in a node pool with same spec.