Home > Software engineering >  ConfigMap being mounted as a folder instead of file
ConfigMap being mounted as a folder instead of file

Time:11-07

I have a problem mounting 2 files in a pod, one is being treated as a directory for some reason (maybe stupid one, but I looked and looked, couldn't find a solution).

in my config folder there's 2 files:

config
|- log4j.properties
|- server.main.properties

Running StatefulSet, here's the Volumes part of the manifest file:

containers:
 ...
      volumeMounts:
        - mountPath: /usr/local/confluent/config/log4j.properties
          name: log4j-properties
          subPath: log4j.properties
        - mountPath: /usr/local/confluent/config/server.properties
          name: server-properties
          subPath: server.properties
  restartPolicy: Always
  volumes:
    - name: log4j-properties
      configMap:
        name: log4j-properties
        defaultMode: 0777
    - name: server-properties
      configMap:
        name: server-properties
        defaultMode: 0777
volumeClaimTemplates:
- metadata:
    name: confluent-persistent-storage
  spec:
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi

Created ConfigMaps:

kubectl create configmap server-properties --from-file=config/server.main.properties
kubectl create configmap log4j-properties --from-file=config/log4j.properties

kubectl describe pod gives mounted volumes as:

    Volumes:
  confluent-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  confluent-persistent-storage-confluent-0
    ReadOnly:   false
  server-properties:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      server-properties
    Optional:  false
  log4j-properties:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      log4j-properties
    Optional:  false

It's being initialized for 5-6 minutes and in logs I can see that server.properties is not a file, but a folder, and when I exec into pod, I can see that the actual folder is been created instead of file.. What am I doing wrong here?

CodePudding user response:

subPath: server.properties

Wouldn't you want to use it as below?

subPath: server.main.properties

  • Related