Pod的本地卷



我正在尝试创建一个本地卷,以便将日志从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使用这些体积?

尝试:

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

相关内容

  • 没有找到相关文章