How to add nodeSelector to Deployment yaml file?

9.8k views Asked by At

In the pods definition, we add the nodeSelector as a child of spec. But I'm not sure how to add this in deployment yaml file

are we supposed to add it in the template's spec-

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: first-deployment
  labels: 
    app: first
spec:
  replicas: 1
  template:
    metadata:
      name: first-deployment-pod
      label: 
        app: first
    spec:
      containers:
      - name: test
        image: test/test
    nodeSelector:
      testkey: testvalue

 

or do we need to add it in the spec of the deplyment -

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: first-deployment
  labels: 
    app: first
spec:
  replicas: 1
  nodeSelector:
    testkey: testvalue
  template:
    metadata:
      name: first-deployment-pod
      label: 
        app: first
    spec:
      containers:
      - name: test
        image: test/test
    
 
1

There are 1 answers

0
SYN On

It should be at the same level than your containers array:

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: first-deployment
  labels: 
    app: first
spec:
  replicas: 1
  template:
    metadata:
      name: first-deployment-pod
      label: 
        app: first
    spec:
      containers:
      - name: test
        image: test/test
      nodeSelector:
        testkey: testvalue