1

我们正在尝试将一些Keda Scaled Jobs部署到我们的 Kubernetes 集群。我们总是希望每个作业有一个节点。我正在尝试配置 podAntiAffinity 规则,以强制不将作业部署到正在运行具有给定标签的另一个作业(pod)的节点。根据文档和示例,您需要一个topologyKey,即

系统用来表示这种拓扑域的节点标签的键;

在我们的例子中,我们希望使用我们指定的实际标签,而不是主机名。在这种情况下,我们将如何配置我们的规则?

apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
  name: my-scaled-job-name
  namespace: my-namespace
  labels:
    # multiple jobs may have this label
    my-special-label: foo 
spec:
  ...
  jobTargetRef:
    ...
    template:
      spec:
        nodeSelector:
          "beta.kubernetes.io/os": linux
          agentpool: my-agent-pool
        affinity:
          # This anti-affinity rule makes sure a new pod won't start on a node where another one is already running
          podAntiAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
            # Unclear whether this is the right topology key, or if I even need one?   
            - topologyKey: kubernetes.io/hostname 
              labelSelector:
                matchLabels:
                  - my-special-label: foo
        containers:
        - name: my-container
          ...
  # This is the trigger definition - watches the queue for incoming messages
  triggers:
    ...
4

0 回答 0