Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

447
Visualizações
Kubernetes : How to ensure one pod gets scheduled on each worker node?

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

Assume a cluster has the following nodes

Nodes

  1. master/control-plane
  2. worker-1
  3. worker-2
  4. worker-2

Pod I'm working with

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"

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

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

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You should probably use Daemonsets which are exactly made for this purpose of scheduling one pod per node and gets automatically added to new nodes in case of cluster autoscaling.

over 4 years ago · Santiago Trujillo Relatório

0

Concept

There are two important things when it comes to assigning Pods to Nodes - "Affinity" and "AntiAffinity".

  • 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.

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

Node affinity/antiaffinity

Node affinity is conceptually similar to nodeSelector -- it allows you to constrain which nodes your pod is eligible to be scheduled on, based on labels on the node.

Inter-pod affinity/antiaffinity

Inter-pod affinity and anti-affinity allow you to constrain which nodes your pod is eligible to be scheduled based on labels on pods that are already running on the node rather than based on labels on nodes.

Your Solution

Basically what you need is "Antiaffinity" and in that "Pod antiaffinity" instead of Node. So, your solution should look something like below (please note that since I do not have 3 Node cluster so I couldn't test this, so thin chances that you might have to do minor code adjustment):
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        labelSelector:
          - matchExpressions:
            - key: worker
              operator: In
              values:
              - log-scraper

Read more over here, and especially go through example over here.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda