docker - Kubernetes:如何将 pod 分配给具有特定标签的所有节点
问题描述
我想在特定节点组中的每个节点上运行某些作业。
Kubernetes 可以像 Swarm 全局模式一样做同样的事情吗?
解决方案
要完成@David Maze 的回答:
DaemonSet用于在每个节点上创建一个 Pod。更多信息在这里。
例子:
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,您可以使用Taints 和 Tolerations概念。污点和容忍一起工作,以确保 Pod 不会被调度到不合适的节点上。有关更多信息,请查看链接。
例如:
您可以将污点添加到节点:
kubectl taint nodes <Node_name> key=value:NoSchedule
之后,Pod 将没有机会在该节点上进行调度,即使从 DaemonSet 也是如此。您可以向 Pod(或在您的情况下为 DaemonSet)添加容忍度,以允许它在具有容忍度的节点上调度:
tolerations:
- key: "key"
operator: "Equal"
value: "value"
effect: "NoSchedule"
推荐阅读
- sql - SSMS——如何加载保存的查询?我保存的 .sql 文件没有找到引用的表
- javascript - 如何在 HTML5 画布中呈现自定义字体?
- python - 在 pymongo 上执行 mongodb 命令
- python - 考虑将此目录添加到 PATH
- python - 如何在 python 中获得 Durbin Watson 测试的 p 值?
- dialogflow-es - 在 Dialogflow 中将参数添加到没有 webhook 的上下文
- python - 在 Python 中将一个 HAR 文件的前 N 行复制到另一个文件
- html - jQuery:我如何重置倒数计时器?
- sas - 使用 PROC FORMAT 和 PROC FCMP 转换 SAS 中的值
- python - Pip 无法安装库,我不知道为什么(chatterbot)