在不同的节点上运行两个kubernetes豆荚



是否有一种方法告诉kubernetes永远不会在同一节点上运行两个豆荚,一个示例我有两个pods副本,我希望它们始终在 zone1/zone2上分布,而永远不会在同一中分布区域一起。

apiVersion: app/v1
kind: Deployment
metadata:
  name: testApp
  labels:
    app: testApp-front
  namespace: 
spec:
  replicas: 2
  selector:
    matchLabels:
      app: testApp-front
  template:
    metadata:
      labels:
        app: testApp-front
    spec:      
      nodeSelector:
        failure-domain.beta.kubernetes.io/zone: zone1

似乎可以使用interpod亲和力完成:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-server
spec:
  selector:
    matchLabels:
      app: testApp-front
  replicas: 3
  template:
    metadata:
      labels:
        app: testApp-front
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - testApp-front
            topologyKey: "kubernetes.io/hostname"
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - store
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: web-testApp-front
        image: nginx:1.12-alpine

您可以在此处看到完整的示例

我认为您需要POD抗亲属的概念。这是在一个集群之内,请注意POD不驻留在一个工人节点上。https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affility-and-anti-affinity

非常简单,您可以使用deamon设置来运行Dixfrent节点中的每个POD,或者正如其他人所说的那样,您可以使用Pod Anti-offinity

K8S调度程序是一件智能的软件。

  1. kubernetes调度程序将首先确定可以根据您的亲和力/抗差/资源限制/etc的所有可能的节点。

  2. 之后,调度程序将找到可以部署POD的最佳节点。调度程序将自动安排豆荚在单独的可用性区域和单独的节点上,如果可能的话,则可以在单独的节点上进行。

P.S。如果您从不希望POD的2个复制品在同一节点上,请定义抗亲和力规则。

最新更新