如何将 PersistentVolume 部署到主节点以外的所有节点?

如何将 PersistentVolume 部署到主节点以外的所有节点?

我曾尝试过kubectl apply这个文件:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: app-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /app
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchFields:
            - key: metadata.labels.node-role.kubernetes.io/master
              operator: NotIn
              values:
                - ""
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: default-app-pvc
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

但我明白:

The PersistentVolume "app-pv" is invalid: spec.nodeAffinity.required.nodeSelectorTerms[0].matchFields[0].key: Invalid value: "metadata.labels.node-role.kubernetes.io/master": not a valid field selector key

答案1

标签需要用 来指定matchExpressions,而不是matchFields。因此matchFields需要将部分替换为:

        - matchExpressions:
            - key: node-role.kubernetes.io/master
              operator: NotIn
              values:
                - ""

相关内容