Unable to mount Kubernetes Secret as a File in Pod

3/30/2018

I am trying to mount a config file created as a secret to a specific path in a pod. However, the mount path on the pod is always generated as a directory. Could someone tell me what am I doing wrong?

> kubectl get secrets config
NAME      TYPE      DATA      AGE
config    Opaque    1         29m

pod yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd-plus-secret
spec:
  containers:
  - image: ubuntu
    name: bash
    stdin: true
    tty: true
    volumeMounts:
      - name: "config"
        mountPath: "/mnt/configFile"
        subPath: "configFile"
  volumes:
  - name: "config"
    secret:
      secretName: "config"

After the pod is created, I try to read the file on the pod, and get:

cat: /mnt/configFile: Is a directory

I am using: kubernetes client version 1.9.0 and server version 1.8.6

-- Bonkers
kubernetes
kubernetes-secrets

1 Answer

3/31/2018

The syntax you want is to select just the secret's items:, and not try to use subPath in that manner. It's documented in SecretVolumeSource

  volumes:
  - name: config
    secret:
      secretName: config
      items:
      - key: configFile
        path: configFile
-- mdaniel
Source: StackOverflow