Can volumeMounts: in kubernetes pod be optional

2/1/2020

I have certain requirements where volumeMounts: should be an optional field.

spec:
      volumes:
        -
          name: aaa
          secret:
            secretName: aaa-certs
      containers:
        -
          name: my-celery
          volumeMounts:
            -
              name: aaa
              mountPath: /tmp/aaa_certs
              readOnly: true

If secret is present then it will mount, else create an empty folder. Is this possible

-- Goutam
kubernetes
kubernetes-pod

2 Answers

2/27/2020

Secret volumes can be marked as optional using tag "optional: true", and result in empty directories if the associated secret doesn't exist, rather than blocking pod startup.

Example:

spec:
      volumes:
        -
          name: aaa
          secret:
            secretName: aaa-certs
            optional: true
      containers:
        -
          name: my-celery
          volumeMounts:
            -
              name: aaa
              mountPath: /tmp/aaa_certs
              readOnly: true
-- Parshad
Source: StackOverflow

2/1/2020

No, that is not possible. You would need a higher level system like Helm or an operator to manage that kind of dynamic configuration.

-- coderanger
Source: StackOverflow