简体   繁体   English

Kubernetes:如何将Pod分配给具有特定标签的所有节点

[英]Kubernetes: how to assign pods to all nodes with sepcific label

I want to run certain job on every single node in specific node groups. 我想在特定节点组中的每个单个节点上运行某些作业。
Can kubernetes do the same thing like Swarm global mode? kubernetes可以做与Swarm全局模式一样的事情吗?

To complete @David Maze answer: 要完成@David Maze答案:

A DaemonSet is used to create a Pod on each Node. DaemonSet用于在每个节点上创建Pod。 More information here . 更多信息在这里

Example: 例:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: fluentd-elasticsearch
        image: k8s.gcr.io/fluentd-elasticsearch:1.20
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers

If you want to schedule Pods not on every Node, you can use Taints and Tolerations concept. 如果您不希望在每个节点上计划Pod,则可以使用“ 污染和容忍”概念。 Taints and tolerations work together to ensure that pods are not scheduled onto inappropriate nodes. 污渍和容忍度共同作用,以确保未将豆荚安排在不适当的节点上。 For more information, look through the link . 有关更多信息,请通过链接查看。

For example: 例如:

You can add a Taint to a Node: 您可以将污染添加到节点:

kubectl taint nodes <Node_name> key=value:NoSchedule

After that, Pods will have no opportunity to schedule on that Node, even from a DaemonSet. 之后,即使从DaemonSet,Pods也将没有机会在该Node上进行调度。 You can add toleration to a Pod (or to a DaemonSet in your case) to allow it schedule on the Node with the toleration: 您可以向Pod(或您的情况下的DaemonSet)添加容差,以允许其在具有容差的Node上进行调度:

tolerations:
- key: "key"
  operator: "Equal"
  value: "value"
  effect: "NoSchedule"

您正在寻找DaemonSet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 能否在Replication Controller中将两个Pod分配给Kubernetes上的两个不同节点? - Can Assign two Pods in Replication Controller to the two Different Nodes on Kubernetes? 如何在Kubernetes集群上获取所有正在运行的POD - How to get all running PODs on Kubernetes cluster Kubernetes:kubectl 顶级节点/Pod 不工作 - Kubernetes: kubectl top nodes/pods not working 在不同节点上运行两个kubernetes pod - Running two kubernetes pods on differents nodes 如何删除 kubernetes 中的待处理 pod? - How to delete pending pods in kubernetes? 如何使用Ansible为docker swarm集群的节点部分分配标签? - How to assign label to nodes part of docker swarm cluster using Ansible? 无法在Kubernetes中的不同节点上运行的pod之间进行通信 - Unable to communicate between pods running on different nodes in Kubernetes Kubernetes:使用 kubeadm 构建集群后,节点/Pod 未使用 kubectl 显示 - Kubernetes: Nodes/Pods not showing with kubectl after building cluster with kubeadm 没有节点可用于计划Pod-在没有VM的情况下本地运行Kubernetes - no nodes available to schedule pods - Running Kubernetes Locally with No VM Kube.netes AutoScaler 或更改 AWS 中的 Desired Nodes 过早终止 Docker Pod - Kubernetes AutoScaler or changing Desired Nodes in AWS prematurely terminates Docker Pods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM