<p>I'm looking to create a statefulset using affinity. I have added a label to my 3 nodes. Two of them have area=area1 and one node has area=area2. I'm looking to run my statefulset pods only on the nodes with area=area1. It's not working. I'm getting an error from the scheduler that no nodes were matched. I'm running Kubernetes v1.7.4</p>

<p>Yaml:</p>

<pre><code>apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: stateful-bcs
spec:
  serviceName: mybcs
  replicas: 2
  template:
    metadata:
      labels:
       app: simplecount
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: area
                operator: In
                values:
                - area1
      containers:
        - name: test1
          image: XXXX.azurecr.io/simple
          env:
            - name: SIMPLE_SERVICE_NAME
              valueFrom:
                fieldRef:
              fieldPath: metadata.name
         command:
            - ./simplecount
            - "$(SIMPLE_SERVICE_NAME)"
      imagePullSecrets:
       - name: XXXXXXX
      restartPolicy: Always
</code></pre>

<p>You should be using <code>nodeAffinity</code> not <code>podAffinity</code>, <code>podAffinity</code> is "based on labels on pods that are already running on the node rather than based on labels on nodes" (<a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/assign-pod-node/</a>).</p>
