1. 文档
https://kubernetes.io/zh-cn/docs/concepts/scheduling-eviction/assign-pod-node/
2. 说明
nodeSelector
是节点选择约束的最简单推荐形式。
你可以将 nodeSelector
字段添加到 Pod 的规约中设置你希望目标节点所具有的节点标签。 Kubernetes 只会将 Pod 调度到拥有你所指定的每个标签的节点上。
3. 实例
此处省略各种前提
3.1. zookeeper部署选择master.cluster.k8s的节点
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: kafka
namespace: kafka
spec:
selector:
matchLabels:
app: kafka
serviceName: kafka-svc
replicas: 3
template:
metadata:
labels:
app: kafka
spec:
nodeSelector:
kubernetes.io/hostname: master.cluster.k8s
3.2. 效果
只部署在mster.cluster.k8s
qiteck@server:~/program/docker_service/kafka$ sudo kubectl get pods -n kafka -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kafka-0 1/1 Running 0 4m34s 10.244.0.162 master.cluster.k8s <none> <none>
kafka-1 1/1 Running 0 89s 10.244.0.163 master.cluster.k8s <none> <none>
kafka-2 1/1 Running 0 67s 10.244.0.164 master.cluster.k8s <none> <none>
标签:kubernetes,nodeSelector,kafka,cluster,master,k8s,节点 From: https://www.cnblogs.com/zhanchenjin/p/17088695.html