1

I have several secrets that are mounted and need to be read as a properties file. It seems kubernetes can't mount them as a single file so I'm trying to concatenate the files after the pod starts. I tried running a cat command in a postStart handler but it seems execute before the secrets are mounted as I get this error:

Error: failed to create containerd task: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "cat /properties/S3Secret /properties/S3Key >> /properties/dbPassword": stat cat /properties/S3Secret /properties/S3Key >> /properties/dbPassword: no such file or directory: unknown

Then here is the yaml.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: K8S_ID
spec:
  selector:
    matchLabels:
      app: K8S_ID
  replicas: 1
  template:
    metadata:
      labels:
        app: K8S_ID
    spec:
      containers:
        - name: K8S_ID
          image: IMAGE_NAME
          ports:
            - containerPort: 8080
          env:
            - name: PROPERTIES_FILE
              value: "/properties/dbPassword"
          volumeMounts:
            - name: secret-properties
              mountPath: "/properties"
          lifecycle:
            postStart:
              exec:
                command: ["cat /properties/S3Secret /properties/S3Key >> /properties/dbPassword"]
      volumes:
        - name: secret-properties
          secret:
            secretName: secret-properties
            items:
              - key: SECRET_ITEM
                path: dbPassword
              - key: S3Key
                path: S3Key
              - key: S3Secret
                path: S3Secret
EricWoody
  • 11
  • 1

1 Answers1

1

You need a shell session for your command like this:

...
lifecycle:
  postStart:
    exec:
      command: ["/bin/sh","-c","cat /properties/S3Secret /properties/S3Key >> /properties/dbPassword"]
...
gohm'c
  • 13,492
  • 1
  • 9
  • 16