Kubernetes Node Affinity和statefulsets

时间:2017-10-03 20:47:38

标签: kubernetes statefulset

我希望使用affinity创建一个statefulset。我在3个节点上添加了标签。其中两个有area = area1,一个节点有area = area2。我希望仅在area = area1的节点上运行我的状态集pod。它不起作用。我从调度程序收到错误,没有匹配任何节点。我正在运行Kubernetes v1.7.4

YAML:

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

1 个答案:

答案 0 :(得分:2)

您应该使用nodeAffinity而非podAffinitypodAffinity“基于已在节点上运行的pod上的标签,而不是基于节点上的标签”({{3 }})。