簡體   English   中英

在不同節點上運行兩個kubernetes pod

[英]Running two kubernetes pods on differents nodes

有沒有辦法告訴Kubernetes永遠不會在同一個節點上運行兩個pod,例如我有兩個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 Affinity完成,你可以看到:

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/#affinity-and-anti-affinity

非常簡單,你可以使用deamon set來運行不同節點中的每個pod,或者其他人說你可以使用pod反關聯

k8s調度程序是一個智能軟件。

  1. kubernetes調度程序將首先根據您的親和力/反關聯性/資源限制/等確定可以部署pod的所有可能節點。

  2. 之后,調度程序將找到可以部署pod的最佳節點。 如果可能的話,調度程序將自動將pod安排在單獨的可用區域和單獨的節點上。

PS如果您從不希望pod的2個副本位於同一節點上,請定義反關聯性規則。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM