在过去的几年里,我在Docker公司工作过很多,但在库伯奈特斯问题上,我是个新手。我从今天开始,与我过去用码头群思考的方式相比,我很难理解Pod概念的有用性。
假设我有一个带有7台功能强大的机器的集群,并且我有以下堆栈:
. swarm =‘swarm 1’>用节点标签处理容器分布,例如我将三台机器和卡桑德拉容器配置标记为C_HOST,2台机器和Kafka配置为K_HOST,.群部署将正确地放置每个容器。
我有以下问题:
发布于 2019-03-01 13:04:22
使用荚反亲和力,您可以确保一个荚是不与其他荚与特定的标签。
所以说,你有一个标签“应用”价值“卡桑德拉”,“卡夫卡”,“我的生产者”和“我的消费者”。
由于您想让cassandra、kafka和my-producer单独在专用节点上,所以您只需配置与所有现有标签的反亲和力:
(完整模式请参见https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ )
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- cassandra
- kafka
- my-producer
- my-consumer
这是一个" pod“资源,所以您可以在一个部署中(在这个部署中还定义了多少个副本)在pod模板中定义它。
由于您希望在同一个节点上运行我的使用者的三个实例(或者说,您实际上并不关心它们在哪里运行,因为现在只剩下一个节点),所以您不需要定义任何关于亲和力或反亲和力的内容:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-consumer
namespace: default
labels:
app: my-consumer
spec:
selector:
matchLabels:
app: my-consumer
replicas: 3 # here you set the number of replicas that should run
template: # this is the pod template
metadata:
labels:
app: my-consumer # now this is the label you can set an anti-affinity to
spec:
containers:
- image: ${IMAGE}
name: my-consumer
# affinity:
# now here below this you'd put the affinity-settings from above
# for the other deployments
发布于 2019-03-01 12:43:26
您仍然可以使用节点标签和nodeSelector参数。
您可以使用kubectl添加节点标签..。
kubectl label nodes <node-name> <label-key>=<label-value>
将标签添加到所选节点。
但更先进的方法是使用亲和力来分发豆荚.
https://stackoverflow.com/questions/54944755
复制相似问题