k8s Error: failed to prepare subPath for volumeMount "custom-logo" of container "grafana"
前言
使用 k8s
挂载卷文件时,使用了 hostPath
,type: File
volumeMounts:
- mountPath: /usr/share/grafana/public/img/grafana_icon.svg
name: custom-logo
subPath: grafana_icon.svg
volumes:
- hostPath:
path: /root/test/logo.svg
type: File
name: custom-logo
结果报错,kubectl describe pod
:
Error: failed to prepare subPath for volumeMount "volume-mount-name" of container "container-name"
报错原因为找不到 subPath
,随后使用了 initContainers
,在 busybox
镜像的 mkdir
命令初始化创建该目录:
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
initContainers:
- name: create-directories
image: busybox
command: ['sh', '-c', 'mkdir -p /usr/share/grafana/public/img']
volumeMounts:
- name: custom-logo
mountPath: /usr/share/grafana/public/img
containers:
- name: grafana
image: grafana/grafana:latest
ports:
- containerPort: 3000
volumeMounts:
- name: custom-logo
mountPath: /usr/share/grafana/public/img/grafana_icon.svg
subPath: grafana_icon.svg
volumes:
- name: custom-logo
hostPath:
path: /root/test/logo.svg
这时 pod
状态为 Init:CrashLoopBackOff
,而 kubectl describe pod
,报错 Back-off restarting failed container
,索性就不使用 subPath
了。
最终写法
volumeMounts:
- mountPath: /usr/share/grafana/public/img/grafana_icon.svg
name: custom-logo
volumes:
- hostPath:
path: /root/test/logo.svg
type: File
name: custom-logo
成功挂载使用了 /root/test/logo.svg
文件。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2020-05-23 laravel-echo-server 启动报错 [ioredis] Unhandled error event: ReplyError: NOAUTH Authentication required.
2020-05-23 laravel proc_get_status() has been disabled for security reasons
2020-05-23 laravel The Process class relies on proc_open, which is not available on your PHP installation.
2019-05-23 Laravel 虚拟开发环境 Homestead 密码
2019-05-23 优化mysql
2019-05-23 MySQL 整型
2019-05-23 MySQL索引原理以及查询优化