kubernetes - Hybrid between replicaset and daemonset
问题描述
Is there such a thing as a hybrid between a replicaset and a daemonset. I want to specify that I always want to have 2 pods up. But those pods must never be on the same node. (and I have like 10 nodes) Is there a way I can achieve this?
解决方案
在部署或副本集中,您可以使用 podAffinity 和 podAntiaffinity。
pod 间亲和性和反亲和性允许您基于节点上已经运行的 pod 上的标签而不是基于节点上的标签来限制您的 pod 有资格调度的节点。
规则的形式是“如果 X 已经在运行一个或多个满足规则 Y 的 Pod,则该 Pod 应该(或者,在反亲和的情况下,不应该)在 X 中运行”。Y 表示为具有可选关联命名空间列表的 LabelSelector。
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- nginx
topologyKey: "kubernetes.io/hostname"
上面的示例 nginx pod1 和 pod2 永远不会被安排在同一个节点上。
在官方文档中查找更多详细信息。
推荐阅读
- huawei-mobile-services - 带有 HMS Core 版本 5.0.1.307 的 mReferrerClient.getInstallReferrer() 中的 IOException
- javascript - 使用 flexbox 使用 justify-content 之间的空间
- oauth-2.0 - 生成令牌时忽略无效范围
- sql - JD Edwards E1 (DB2) 的复杂 SQL 查询帮助
- c++ - C++ 程序报告“进程终止,状态为 -1073741510”
- javascript - 如何与 Shopify Storefront 通信并将 JS 片段添加到产品页面
- meteor - 将 curl 命令转换为 Meteor 的 HTTP 调用
- android - 使用具有复杂对象的 KSoap2 调用 WCF 服务。WCF 接收空值
- stm32 - 我可以使用具有 1 级闪存读出保护的 STM32F303RDTx 的 ROM 引导加载程序吗?
- google-cloud-storage - 使用 Dataprep 的 ETL - 联合数据集