本文介绍了Kubernetes:如何确保在每个工作节点上安排一个Pod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:在每个节点上安排一次至少一次,但不超过一次的pod(即日志抓取器")

Goal : Have one pod (namely 'log-scraper') get scheduled on every node at least once but no more than once

假设集群具有以下节点

节点

  1. 主/控制平面
  2. worker-1
  3. worker-2
  4. worker-2

我正在使用的Pod

apiVersion: v1
kind: Pod
metadata:
  name: log-scraper
spec:
  volumes:
  - name: container-log-dir
    hostPath:
      path: /var/log/containers
  containers:
    - image: "logScraper:latest"
      name: log-munger
      volumeMounts:
      - name: container-log-dir
        mountPath: /var/log/logging-app

添加关联性以仅选择工作"节点(或非主要节点)

Adding affinity to select only 'worker' nodes (or non-mater nodes)

  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
            - key: "worker"
              operator: In
              values:
              - "true"

问题1:如何确保每个节点运行一对一的 输入 log-scraper

Question 1: How do I ensure every node runs ONE-AND-ONLY-ONE pod of type log-scraper

问题2:应该使用/添加哪些其他清单来实现这一目标?

Question 2: What other manifests should be applied/added to achieve this?

推荐答案

概念

将Pod分配给节点时,有两件重要的事情-亲和力" "AntiAffinity" .

  • 亲和力基本上会根据给定的条件进行选择,而反亲和力会避免基于给定的条件进行选择.
  • 通过亲和力"和反亲和力",您可以使用诸如 In NotIn Exist DoesNotExist 之类的运算符, Gt Lt .当您使用 NotIn DoesNotExist 时,它将变为反亲和力.
  • Affinity will basically select based on given criteria while anti-affinity will avoid based on given criteria.
  • With Affinity and Anti-affinity, you can use operators like In, NotIn, Exist, DoesNotExist, Gt and Lt. When you use NotIn and DoesNotExist, then it becomes anti-affinity.

现在,在亲和力/反亲和力"中,您有2个选择-节点亲和力/反亲和力"和"pod-pod亲和力/抗亲和力"

Now, in Affinity/Antiaffinity, you have 2 choices - Node affinity/antiaffinity and Inter-pod affinity/antiaffinity

  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        labelSelector:
          - matchExpressions:
            - key: worker
              operator: In
              values:
              - log-scraper


此处查看更多内容,尤其是通过此处.

这篇关于Kubernetes:如何确保在每个工作节点上安排一个Pod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 07:36