kubernetes Pod的本地音量

ffscu2ro  于 2022-12-26  发布在  Kubernetes
关注(0)|答案(1)|浏览(209)

我尝试创建一个本地卷,以便将日志从Pod保存到隔离环境中的节点。因此,我尝试在具有tier=production标记的特定节点上创建一个PV和一个PVC。我已将该节点标记为:

$ k get nodes --show-labels
NAME             STATUS   ROLES           AGE   VERSION   LABELS
xxx              Ready    Worker          12d   v1.25.2   <lots of lables>,tier=production

在本地卷和存储类文档之后,我创建了以下yaml来部署卷、claim和pod:

---
# A storage class to define local storage
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

---
# Volume using a local filesystem
apiVersion: v1
kind: PersistentVolume
metadata:
  name: volume-pv
spec:
  capacity:
    storage: 1Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /tmp/nginx/
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: tier
          operator: In
          values:
          - production

---
# Request a claim on the file system volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: volume-claim
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-storage
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi
  selector:
    matchExpressions:
    - key: tier
      operator: In
      values:
      - production

---
# Make a pod that uses the volume
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: tier
            operator: In
            values:
            - production          
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - mountPath: "/var/www/html"
      name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: volume-claim

我的卷可用,但PVC为waiting for first consumer to be created before binding,这是预期的,因为存储类设置为WaitForFirstConsumer。但我的pod从未计划,它给出以下警告:

Warning  FailedScheduling  8m25s  default-scheduler  0/1 nodes are available: 1 node(s) didn't find available persistent volumes to bind. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.

如果我从上面的yaml中删除卷信息,它会部署得很好,所以我不知道是pod的问题还是其他什么问题。我如何让pod使用卷?

cclgggtu

cclgggtu1#

试试看:

...
# Volume using a local filesystem
apiVersion: v1
kind: PersistentVolume
metadata:
  name: volume-pv
  labels:    # <-- add for your PVC selector to match
    tier: production
...

相关问题