Kubernetes部署StatefulSet起步¶
调度¶
我在部署 在Kubernetes集群(z-k8s)部署集成GPU监控的Prometheus和Grafana 时候,期望将 prometheus-stack
中的 StatfulSet
pod prometheus-kube-prometheus-stack-1681-prometheus-0
调度到指定服务器 i-0jl8d8r83kkf3yt5lzh7
,而不是随机分布在集群的任意节点。
但是,和常规的无状态 workload resources(工作负载资源) (例如 Deployment )不同,在 spec
中添加 nodeSelector
( 选择节点(nodeSelector)部署Pod ) 并没有作用(配置修改不报错,但是修改后配置项消失且无效):
...
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: prometheus
creationTimestamp: null
labels:
app.kubernetes.io/instance: kube-prometheus-stack-1681-prometheus
...
spec:
nodeSelector:
telemetry: prometheus
automountServiceAccountToken: true
containers:
...
而且我尝试了 nodeAffinity
也没有成功:
...
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: prometheus
creationTimestamp: null
labels:
...
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: telemetry
operator: In
values:
- prometheus
automountServiceAccountToken: true
containers:
...
Modifying nodeSelector on StatefulSet doesn't reschedule Pods #57838 提到修改StatefulSet不会触发pod调度telemetry: prometheus
备注
StatefulSet 使用 VolumeClaimTemplate
来为每个pod挂载持久化卷(PV)
暂未解决,待研究