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

时间:2018-08-10 03:05:09

标签: docker kubernetes

我想在特定节点组中的每个单个节点上运行某些作业。
kubernetes可以做与Swarm全局模式一样的事情吗?

2 个答案:

答案 0 :(得分:3)

要完成@David Maze的答案,

DaemonSet 用于在每个节点上创建Pod。更多信息here

示例:

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

如果您不希望在每个节点上计划Pod,则可以使用污染和容忍概念。污渍和容忍度共同作用,以确保未将豆荚安排在不适当的节点上。有关更多信息,请浏览link

例如:

您可以将污染添加到节点:

kubectl taint nodes <Node_name> key=value:NoSchedule

此后,即使从DaemonSet中,Pods也将没有机会在该Node上进行调度。 您可以将容忍度添加到Pod(或您的案例中的DaemonSet)中,以允许其在具有容忍度的节点上调度:

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

答案 1 :(得分:0)

您正在寻找DaemonSet