首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我在试图将目录挂载到文件时出错?

为什么我在试图将目录挂载到文件时出错?
EN

DevOps用户
提问于 2021-05-23 10:41:14
回答 1查看 3.1K关注 0票数 2

我有这个prometheus部署清单文件:创建prometheus部署

代码语言:javascript
复制
---
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

但是这个错误是“试图将目录挂载到文件上”

代码语言:javascript
复制
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。

代码语言:javascript
复制
# kubectl get cm -n monitoring
NAME                DATA   AGE
kube-root-ca.crt    1      35h
prometheus-config   1      41m

什么地方可能出了问题?

EN

回答 1

DevOps用户

发布于 2021-05-23 18:24:07

基于volumeMountconfigMap实际上为数据键创建文件。您不需要mountPathsubPath中的文件名

代码语言:javascript
复制
$ cat <

参考:

票数 2
EN
页面原文内容由DevOps提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://devops.stackexchange.com/questions/13970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档