2

I have a problem when trying to mount 2 file into a pods.

Here's the Volumes part of the manifest file:

# Source: squid/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: squid-dev
  labels:
    app: squid
    chart: squid-0.4.1
    release: squid-dev
    heritage: Helm
spec:
  replicas: 2
  updateStrategy:
    type: RollingUpdate
  serviceName: squid-dev
  selector:
    matchLabels:
      app: squid
      chart: squid-0.4.1
      release: squid-dev
      heritage: Helm
  volumeClaimTemplates:
  - metadata:
      name: squid-dev-cache
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 3Gi
  template:
    metadata:
      annotations:
        checksum: checksum
        checksum/config: e51a4d6e552f890604aaa4c47c522653c25cad7ffec5680f67bbaadba6d3c3b2
        checksum/secret: secret
      labels:
        app: squid
        chart: squid-0.4.1
        release: squid-dev
        heritage: Helm
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - "squid"
      containers:
        - name: squid
          image: "honestica/squid:4-ff434982-c47b-47c3-b705-b2adb2730978"
          imagePullPolicy: IfNotPresent
          volumeMounts:
          - name: squid-dev-config
            mountPath: /etc/squid/squid.conf
            subPath: squid.conf
          - name: squid-dev-config
            mountPath: /etc/squid/squid.conf.backup
            subPath: squid.conf.backup
          - name: squid-dev-cache
            mountPath: /var/cache/squid
          ports:
            - name: port3128
              containerPort: 3128
              protocol: TCP
            - name: port8080
              containerPort: 8080
              protocol: TCP
          readinessProbe:
            tcpSocket:
              port: 3128
            failureThreshold: 3
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources:
            {}
      volumes:
      - name: squid-dev-config
        configMap:
          name: squid-dev

And this is manifest of the configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: squid-dev-config
  labels:
    app: squid
    chart: squid-0.4.1
    release: squid-dev
    heritage: Helm
data:
  squid.conf: |
    acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
    acl localnet src 10.0.0.0/8   # RFC 1918 local private network (LAN)
    acl localnet src 100.64.0.0/10    # RFC 6598 shared address space (CGN)
    acl localnet src 169.254.0.0/16   # RFC 3927 link-local (directly plugged) machines
    acl localnet src 172.16.0.0/12    # RFC 1918 local private network (LAN)
    acl localnet src 192.168.0.0/16   # RFC 1918 local private network (LAN)
    acl localnet src fc00::/7         # RFC 4193 local private network range
    acl localnet src fe80::/10        # RFC 4291 link-local (directly plugged) machines
    
    acl SSL_ports port 443 8443 8448 8248 8280
    acl Safe_ports port 80 # http
    acl Safe_ports port 21 # ftp
    acl Safe_ports port 443 # https
    acl Safe_ports port 70 # gopher
    acl Safe_ports port 210 # wais
    #acl Safe_ports port 1025–9999 # unregistered ports
    acl Safe_ports port 280 # http-mgmt
    acl Safe_ports port 488 # gss-http
    acl Safe_ports port 591 # filemaker
    acl Safe_ports port 777 # multiling http
    acl CONNECT method CONNECT
    
    ...
  squid.conf.backup: |
    acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
    acl localnet src 10.0.0.0/8   # RFC 1918 local private network (LAN)
    acl localnet src 100.64.0.0/10    # RFC 6598 shared address space (CGN)
    acl localnet src 169.254.0.0/16   # RFC 3927 link-local (directly plugged) machines
    acl localnet src 172.16.0.0/12    # RFC 1918 local private network (LAN)
    acl localnet src 192.168.0.0/16   # RFC 1918 local private network (LAN)
    acl localnet src fc00::/7         # RFC 4193 local private network range
    acl localnet src fe80::/10        # RFC 4291 link-local (directly plugged) machines
    
    acl SSL_ports port 443 8443 8448 8248 8280
    acl Safe_ports port 80 # http
    acl Safe_ports port 21 # ftp
    acl Safe_ports port 443 # https
    acl Safe_ports port 70 # gopher
    acl Safe_ports port 210 # wais
    #acl Safe_ports port 1025–9999 # unregistered ports
    acl Safe_ports port 280 # http-mgmt
    acl Safe_ports port 488 # gss-http
    acl Safe_ports port 591 # filemaker
    acl Safe_ports port 777 # multiling http
    acl CONNECT method CONNECT
    
    ...

After using helm to install, I execute into pod and list the folder /etc/squid and result is below:

/ # ls -la /etc/squid/
total 388
drwxr-xr-x    1 root     root            31 Mar 25 19:09 .
drwxr-xr-x    1 root     root            19 Mar 25 19:09 ..
-rw-r--r--    1 root     root           692 Oct 30 23:43 cachemgr.conf
-rw-r--r--    1 root     root           692 Oct 30 23:43 cachemgr.conf.default
-rw-r--r--    1 root     root          1800 Oct 30 23:43 errorpage.css
-rw-r--r--    1 root     root          1800 Oct 30 23:43 errorpage.css.default
-rw-r--r--    1 root     root         12077 Oct 30 23:43 mime.conf
-rw-r--r--    1 root     root         12077 Oct 30 23:43 mime.conf.default
-rw-r--r--    1 root     root          3598 Mar 25 19:09 squid.conf
drwxrwxrwx    2 root     root             6 Mar 25 19:09 squid.conf.backup
-rw-r--r--    1 root     root          2526 Oct 30 23:43 squid.conf.default
-rw-r--r--    1 root     root        344566 Oct 30 23:43 squid.conf.documented

Why squid.conf is a file and squid.conf.backup is a folder? I have change the name of squid.conf.backup to anything else but it 's still create a folder instead of a file, and if we choose the name same as a file in this folder ex: cachemgr.conf

  Warning  Failed     3s (x3 over 15s)  kubelet            Error: failed to start container "squid": Error response from daemon: 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/411dc966-ed7d-494c-b9b7-4abfe1639f00/volume-subpaths/squid-dev-config/squid/0" to rootfs at "/etc/squid/cachemgr.conf" caused: mount through procfd: 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

Only squid.conf can be mounted as a file, anything else will be mounted as a folder.

How can I fix this? Can anyone explain about this behavior please?

I have search on google and helm chart of fluent-bit can mount 2 files into pods using only 1 configmap: https://github.com/fluent/helm-charts/tree/main/charts/fluent-bit

Kubectl version:

Server Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.11-eks-f17b81", GitCommit:"f17b810c9e5a82200d28b6210b458497ddfcf31b", GitTreeState:"clean", BuildDate:"2021-10-15T21:46:21Z", GoVersion:"go1.15.15", Compiler:"gc", Platform:"linux/amd64"}

Helm version:

version.BuildInfo{Version:"v3.3.4", GitCommit:"a61ce5633af99708171414353ed49547cf05013d", GitTreeState:"clean", GoVersion:"go1.14.9"}
Tho Quach
  • 1,347
  • 10
  • 26
  • Did you see [did similar question](https://stackoverflow.com/questions/45972812/are-you-trying-to-mount-a-directory-onto-a-file-or-vice-versa)? Is it helpful for you? – Mikołaj Głodziak Mar 28 '22 at 15:41
  • @MikołajGłodziak It does not similar to mine. – Tho Quach Mar 29 '22 at 08:30
  • Did you try to upgrade your Kubernetes version? You are using unsupported (deprecated) one. – Mikołaj Głodziak Mar 30 '22 at 13:33
  • @MikołajGłodziak I see the message about deprecated kubectl version too but I think it does not relate to my problem, because we have older k8s cluster and everything is well. – Tho Quach Mar 31 '22 at 04:12
  • Are you really sure, that you are not mounting files to dirs (or vice versa)? I have newest version of k8s, similar situation and everything works well. – Mikołaj Głodziak Mar 31 '22 at 07:39
  • Yes because I learn from helm chart of fluent-bit, I have deployed fluent-bit and I can mount 2 files into pods, the problem only happen when I try to deploy squid using above helm chart. @MikołajGłodziak – Tho Quach Mar 31 '22 at 07:45

0 Answers0