0

I'm testing with ceph-csi pv and pvc's on a kubernetes cluster (version 1.21.2). Trying to assign a small pv for a dnsmasq pod to be able to change dnsmasq.conf without restarting the pod.

apiVersion: v1
metadata:
  name: dnsmasq-pvc
  namespace: vt
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
  storageClassName: ceph-rbd-sc
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dnsmasq
  namespace: vt
  labels:
    app: dnsmasq
spec:
  serviceName: "dnsmasq"
  replicas: 1
  selector:
    matchLabels:
      app: dnsmasq
  template:
    metadata:
      labels:
        app: dnsmasq
    spec:
      hostname: dnsmasq
      containers:
      - name: dnsmasq
        image: jpillora/dnsmasq
        ports:
        - containerPort: 8080
        imagePullPolicy: IfNotPresent
        env:
        - name: HTTP_USER
          value: "user"
        - name: HTTP_PASS
          value: "password"
        volumeMounts:
        - mountPath: /etc/dnsmasq.conf
          name: dnsmasq-pvc
          subPath: dnsmasq.conf
      volumes:
      - name: dnsmasq-pvc
        persistentVolumeClaim:
          claimName: dnsmasq-pvc
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
          - 8.8.8.8

After i apply the yaml file and i get the error below:

Error: failed to create containerd task: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/var/lib/kubelet/pods/48d9fac5-1603-416c-83b1-d57de22e1c81/volume-subpaths/pvc-d197a21c-107c-47a9-b334-fa4f97375b57/dnsmasq/0" to rootfs at "/etc/dnsmasq.conf" caused: mount through procfd: not a directory: unknown

How can i resolve this?

Nyquillus
  • 179
  • 1
  • 5
  • 23
  • 2
    You must mount the volume as a directory, you cannot mount it as a file. – Jonas Jul 06 '21 at 15:48
  • Have you tried the solution that is included in [this answer](https://stackoverflow.com/questions/51648465/how-to-mount-data-file-in-kubernetes-via-pvc) (the `PVC` part)? Also, if this is a single file, have you considered using a `Secret` or a `Configmap` mounted as a `Volume` ([they will update eventually](https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically)). – Dawid Kruk Jul 07 '21 at 12:05
  • Did you fix this somehow? I am getting the same error. Thank you in advance and regards – Javier Guzmán Jan 12 '22 at 05:59
  • I resolved this issue by mounting a ConfigMap on /etc/dnsmasq.conf which has the configuration conf-dir=/etc/dnsmasq.d,*.conf and mounting a persistent volume to /etc/dnsmasq.d folder. – Nyquillus Jan 12 '22 at 12:30

2 Answers2

0
  • as @jonas mentioned modifying volumeMount.mountPath value to a directory
apiVersion: v1
metadata:
  name: dnsmasq-pvc
  namespace: vt
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
  storageClassName: ceph-rbd-sc
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dnsmasq
  namespace: vt
  labels:
    app: dnsmasq
spec:
  serviceName: "dnsmasq"
  replicas: 1
  selector:
    matchLabels:
      app: dnsmasq
  template:
    metadata:
      labels:
        app: dnsmasq
    spec:
      hostname: dnsmasq
      containers:
      - name: dnsmasq
        image: jpillora/dnsmasq
        ports:
        - containerPort: 8080
        imagePullPolicy: IfNotPresent
        env:
        - name: HTTP_USER
          value: "user"
        - name: HTTP_PASS
          value: "password"
        volumeMounts:
        - mountPath: /etc/
          name: dnsmasq-pvc
          subPath: dnsmasq.conf
      volumes:
      - name: dnsmasq-pvc
        persistentVolumeClaim:
          claimName: dnsmasq-pvc
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
          - 8.8.8.8
confused genius
  • 2,876
  • 2
  • 16
  • 29
0

I know this question is old, but just in case it helps somebody, I had a similar issue, but I was trying to mount a Secret instead. I wanted to mount a single Secret's key as a file, instead of a folder. I solved it by commenting the subPath inside volumeMounts.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache
spec:
  replicas: 1
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      app: apache
  template:
    metadata:
      labels:
        app: apache
    spec:
      volumes:
        - name: config
          secret:
            secretName: php-ini
            items:
              - key: config.ini
                path: config.ini
      containers:
        - name: main
          image: <image>
          imagePullPolicy: Always
          resources:
            limits:
              cpu: 100m
              memory: 200Mi
            requests:
              cpu: 5m
              memory: 10Mi
          volumeMounts:
            - name: config
              mountPath: /mnt/
              #subPath: config.ini
              readOnly: true
          ports:
            - containerPort: 443