gpt4 book ai didi

kubernetes - 在 kubernetes 中找不到持久卷声明

转载 作者:行者123 更新时间:2023-12-04 16:04:40 26 4
gpt4 key购买 nike

目前我尝试实现 持久卷 在我的 yaml 文件中。
我在互联网上阅读了很多文档,但我不明白为什么当我转到仪表板 Pane 时会收到此消息

persistentvolumeclaim "karaf-conf" not found



pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: karafpod
spec:
containers:
- name: karaf
image: xxx/karaf:ids-1.1.0
volumeMounts:
- name: karaf-conf-storage
mountPath: "/apps/karaf/etc"
volumes:
- name: karaf-conf-storage
persistentVolumeClaim:
claimName: karaf-conf-claim

PersistentVolumeClaimKaraf.yml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: karaf-conf-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi

PersistentVolume.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: karaf-conf
labels:
type: local
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/apps/karaf/etc"

您将在命令的结果下方找到 kubectl 获取光伏
NAME                             CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS        CLAIM                         STORAGECLASS   REASON    AGE
karaf-conf 100Mi RWO Retain Terminating default/karaf-conf-claim 17h
karaf-conf-persistentvolume 100Mi RWO Retain Released default/karaf-conf 1h

kubectl 获取 pvc
NAME                  STATUS        VOLUME          CAPACITY   ACCESS MODES   STORAGECLASS   AGE
karaf-conf-claim Terminating karaf-conf 10Mi RWO manual 17h

最佳答案

使用 hostPath,您不需要 PersistentVolume 或 PersistentVolumeClaim 对象,因此根据您的需要,这可能会更容易:

# file: pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: karafpod
spec:
containers:
- name: karaf
image: xxx/karaf:ids-1.1.0
volumeMounts:
- name: karaf-conf-storage
mountPath: "/apps/karaf/etc" # Path mounted in container

# Use hostPath here
volumes:
- name: karaf-conf-storage
hostPath:
path: "/apps/karaf/etc" # Path from the host

然后删除另外两个 .yaml 文件 PersistentVolumeClaimKaraf.ymlPersistentVolume.yml
官方文档见: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath

编辑:注意到原始帖子中的 spec.containers.VolumeMounts.mountPath 和 spec.containers.volumes.hostPath.path 是相同的,因此在 yaml 中添加了注释以阐明每个的目的。

关于kubernetes - 在 kubernetes 中找不到持久卷声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51060027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com