文档中给出的示例代码没有说明它可以在哪些项目上使用。你能在部署/状态集/持久卷上使用节点选择器吗?另外,当我将节点选择器放在
.spec.nodeSelector本身
spec:
nodeSelector:
workload: node-selector-app当我尝试部署/statefulset/persistentvolume的演练运行时,我得到一个验证错误。那么nodeSelector只能在Pod上使用吗?
发布于 2020-03-26 23:50:31
在persistentVolumes中不能使用nodeSelector。pod模板的规格部分应包含nodeSelector。使用nodeSelector的部署示例
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
nodeSelector:
workload: node-selector-app在persistentVolume中,您可以使用nodeAffinity
kubectl explain persistentVolume.spec.nodeAffinity
KIND: PersistentVolume
VERSION: v1
RESOURCE: nodeAffinity <Object>
DESCRIPTION:
NodeAffinity defines constraints that limit what nodes this volume can be
accessed from. This field influences the scheduling of pods that use this
volume.
VolumeNodeAffinity defines constraints that limit what nodes this volume
can be accessed from.
FIELDS:
required <Object>
Required specifies hard node constraints that must be met.举个例子:
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-local-pv
spec:
capacity:
storage: 500Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/disks/vol1
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- my-nodehttps://stackoverflow.com/questions/60870978
复制相似问题