Node Selector

Describe about Node Selector

Node Selector is a property that allows you to specify the node when creating the Pod or any other resource. The value of this property is derived from the label of the Node. Example:

We aim to deploy the Pod on the Node with the highest available resources.

  1. We add the label to Node A by using this command: kubectl label node <node_name> <label_key>=<label_value>

  2. Add the Node Selector property in Pod template

# Pod Template
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels: 
    name: nginx
spec: 
  containers:
  - name: nginx
    image: nginx 
    ports:
      - containerPort: 8080
  nodeSelector: 
    <label_key>: <label_value>
          

Disadvantage of this strategy:

  • If we label Node A as "Large" and Node B as "Medium," our requirement is to deploy the Pod on a Node with either "Large" or "Medium" resources. However, the current configuration does not allow for this preference.

Last updated