Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在kubernetes中使用节点选择器_Kubernetes - Fatal编程技术网

如何在kubernetes中使用节点选择器

如何在kubernetes中使用节点选择器,kubernetes,Kubernetes,文档中给出的示例代码没有说明它可以用于哪些项目。您可以在部署/StatefulSet/persistentvolumes上使用节点选择器吗?当我将节点选择器置于 .spec.nodeSelector本身 spec: 节点选择器: 工作负载:节点选择器应用程序 我在尝试对部署/statefulset/persistentvolume进行干运行时遇到验证错误。因此,节点选择器只能在pod上使用吗?节点选择器不能在持久卷中使用。节点选择器应位于pod模板的规范部分。使用节点选择器部署的示例 apiV

文档中给出的示例代码没有说明它可以用于哪些项目。您可以在部署/StatefulSet/persistentvolumes上使用节点选择器吗?当我将节点选择器置于

.spec.nodeSelector本身

spec:
节点选择器:
工作负载:节点选择器应用程序

我在尝试对部署/statefulset/persistentvolume进行干运行时遇到验证错误。因此,节点选择器只能在pod上使用吗?

节点选择器不能在持久卷中使用。
节点选择器应位于pod模板的规范部分。使用
节点选择器部署的示例

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.

啊哈,太棒了。您知道是否可以将nodeSelector与持久卷一起使用吗?我尝试了,但它得到了一个验证错误。如中所述:PV可以指定定义限制此卷可以从哪些节点访问的约束。使用PV的POD将只调度到由节点关联选择的节点。因此,不,我只能指定nodeAffinity,而不能为其指定nodeSelector
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-node