in your CKA labs of node affinity there is question of Set Node Affinity to the deployment to place the pods on node01 only.
Name: blue
Replicas: 3
Image: nginx
NodeAffinity: requiredDuringSchedulingIgnoredDuringExecution
Key: color
values: blue
but i tried to do with ```
preferredDuringSchedulingIgnoredDuringExecution and i use this yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: blue
name: blue
spec:
replicas: 3
selector:
matchLabels:
app: blue
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: blue
spec:
containers:
- image: nginx
name: nginx
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: color
operator: In
values:
- blue
resources: {}
status: {}
but i ran this command : kubectl create -f blue-deploy.yaml
error: error validating “blue-deploy.yaml”: error validating data: [ValidationError(Deployment.spec.template.spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution): invalid type for io.k8s.api.core.v1.NodeAffinity.preferredDuringSchedulingIgnoredDuringExecution: got “map”, expected “array”, ValidationError(Deployment.spec.template.spec.affinity): unknown field “resources” in io.k8s.api.core.v1.Affinity]; if you choose to ignore these errors, turn validation off with --validate=false
It give above error



