Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.38 KB

File metadata and controls

67 lines (51 loc) · 1.38 KB

Node Selectors

In this section, we will take a look at Node Selectors in Kubernetes

We add new property called Node Selector to the spec section and specify the label.

  • The scheduler uses these labels to match and identify the right node to place the pods on.
    apiVersion: v1
    kind: Pod
    metadata:
     name: myapp-pod
    spec:
     containers:
     - name: data-processor
       image: data-processor
     nodeSelector:
      size: Large
    

nsel

  • To label nodes

    Syntax

    $ kubectl label nodes <node-name> <label-key>=<label-value>
    

    Example

    $ kubectl label nodes node-1 size=Large
    

ln

  • To create a pod definition
    apiVersion: v1
    kind: Pod
    metadata:
     name: myapp-pod
    spec:
     containers:
     - name: data-processor
       image: data-processor
     nodeSelector:
      size: Large
    
    $ kubectl create -f pod-definition.yml
    

nsel

Node Selector - Limitations

  • We used a single label and selector to achieve our goal here. But what if our requirement is much more complex.

nsl

  • For this we have Node Affinity and Anti Affinity

K8s Reference Docs