I'm trying to create a statefulset in kubernetes 1.9 with nodeAffinity. I found some examples with a simple nodeselector, but that is not really what I would like to accomplish. I want to make sure that statefulset instances always start on the same node, like this:
I tried labelling the corresponding nodes with the statefulpod-name, and using downward api in nodeselector or nodeaffinity, but I cannot produce a working yaml to do this.
The example:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
matchExpressions:
- key: statefulpodname
operator: In
values:
- valueFrom:
fieldRef:
fieldPath: metadata.name
The error:
ValidationError(StatefulSet.spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution): invalid type for io.k8s.api.core.v1.NodeSelector: got "map", expected "array";
The example:
nodeSelector:
statefulpodname:
- valueFrom:
fieldRef:
fieldPath: metadata.name
The error:
invalid type for io.k8s.api.core.v1.PodSpec.nodeSelector: got "array", expected "string"
Any ideas?
as error states got "map", expected "array";
, try with :
- nodeSelectorTerms:
- matchExpressions:
...