I'm trying to create a DaemonSet with a specific affinity, I want it only to create Pods on nodes with type=prod. I use the following test code:
apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: test0 namespace: kube-system spec: template: metadata: labels: app: test0 spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: type operator: In values: - prod containers: - name: test0 image: gcr.io/google_containers/pause:2.0
However, the kubectl exits with the following error:
error: error validating "test.yaml": error validating data: found invalid field affinity for v1.PodSpec; if you choose to ignore these errors, turn validation off with --validate=false
I'm at a loss as to waht I'm doing wrong here. I tried placing the affinity block under the template block as well, same error.
I should note that the cluster is still Kubernetes 1.4.8, though. Affinity is part of Kubernetes since 1.2, so I don't think that would be the problem?
Found the solution myself, apparently I need to use an annotation instead:
What you have looks perfect to me, if I were to guess why it didn't work it'd problably be due to one of these 2 reasons:
I'm using this (just fiddling with something as an experiment), which seems very similar to what you have an it works as expected for me.