我有这个prometheus部署清单文件:创建prometheus部署
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
namespace: monitoring
labels:
app: prometheus
spec:
replicas: 1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9090"
spec:
nodeSelector:
boardType: aarch64
initContainers:
- name: prometheus-data-permission-setup
image: busybox
command: ["/bin/chmod","-R","777", "/data"]
volumeMounts:
- name: prometheus-data
mountPath: /data
containers:
- name: prometheus
image: rycus86/prometheus:latest
imagePullPolicy: IfNotPresent
args:
- '--storage.tsdb.path=/data'
- '--config.file=/etc/prometheus/prometheus.yml'
command:
- /bin/prometheus
ports:
- name: web
containerPort: 9090
volumeMounts:
- name: config-volume
mountPath: /etc/prometheus/prometheus.yml
subPath: prometheus.yml
- name: prometheus-data
mountPath: /data
readOnly: false
resources:
requests:
cpu: "250m"
ephemeral-storage: "4Gi"
limits:
memory: "200Mi"
cpu: "500m"
ephemeral-storage: "20Gi"
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: config-volume
configMap:
name: prometheus-config
- name: prometheus-data
hostPath:
path: /data
type: Directory
serviceAccountName: prometheus但是这个错误是“试图将目录挂载到文件上”
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 30s default-scheduler Successfully assigned monitoring/prometheus-b568c9967-tmdq7 to rockpro64
Normal Pulling 28s kubelet Pulling image "busybox"
Normal Pulled 26s kubelet Successfully pulled image "busybox" in 1.57966103s
Normal Created 26s kubelet Created container prometheus-data-permission-setup
Normal Started 25s kubelet Started container prometheus-data-permission-setup
Warning Failed 23s kubelet Error: failed to start container "prometheus": Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/kubelet/pods/da8d1a99-a6d0-48f5-ad5e-cbc5db136145/volume-subpaths/config-volume/prometheus/0\\\" to rootfs \\\"/var/lib/docker/overlay2/32aead2ba4f70863e9cf643a1bad1fb0832eb43c217898bfe77cc67ab400d702/merged\\\" at \\\"/var/lib/docker/overlay2/32aead2ba4f70863e9cf643a1bad1fb0832eb43c217898bfe77cc67ab400d702/merged/etc/prometheus/prometheus.yml\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Warning Failed 23s kubelet Error: failed to start container "prometheus": Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/kubelet/pods/da8d1a99-a6d0-48f5-ad5e-cbc5db136145/volume-subpaths/config-volume/prometheus/0\\\" to rootfs \\\"/var/lib/docker/overlay2/9dcb8fa640d8fc93f56755f5daeb2a350c482f5f3f26faee03edb320d52f53ff/merged\\\" at \\\"/var/lib/docker/overlay2/9dcb8fa640d8fc93f56755f5daeb2a350c482f5f3f26faee03edb320d52f53ff/merged/etc/prometheus/prometheus.yml\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Warning BackOff 22s kubelet Back-off restarting failed container
Normal Pulled 7s (x3 over 24s) kubelet Container image "rycus86/prometheus:latest" already present on machine
Normal Created 7s (x3 over 24s) kubelet Created container prometheus
Warning Failed 6s kubelet Error: failed to start container "prometheus": Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/kubelet/pods/da8d1a99-a6d0-48f5-ad5e-cbc5db136145/volume-subpaths/config-volume/prometheus/0\\\" to rootfs \\\"/var/lib/docker/overlay2/5b263ca359000d143fd5f11fb26218ead46eabd1a1aeb39ce1a7b48302a2382c/merged\\\" at \\\"/var/lib/docker/overlay2/5b263ca359000d143fd5f11fb26218ead46eabd1a1aeb39ce1a7b48302a2382c/merged/etc/prometheus/prometheus.yml\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type我已经安装了prometheus-config configmap。
# kubectl get cm -n monitoring
NAME DATA AGE
kube-root-ca.crt 1 35h
prometheus-config 1 41m什么地方可能出了问题?
发布于 2021-05-23 18:24:07
基于volumeMount的configMap实际上为数据键创建文件。您不需要mountPath或subPath中的文件名
$ cat <参考:
https://devops.stackexchange.com/questions/13970
复制相似问题