K8s: deployment valueFrom secretKeyRef optional if the secret is not present

Elvis Ciotti
Jun 15, 2023

We’ve recently introduced a new secret into our k8s environments. Due to the helm chart being shared but the secret being set at different stages, we needed to have the deployment not complaining if the secret wasn’t set. The solution was using the optional keyword.

- name: ENV_NAME
valueFrom:
secretKeyRef:
name: <secrets name>
key: <secrets key>
optional: true

I see the same answer on StackOverflow with more details.

--

--

Elvis Ciotti
Elvis Ciotti

Written by Elvis Ciotti

Software Contractor — Java, Spring, k8s, AWS, Javascript @ London - hire me at https://elvisciotti.github.io/

No responses yet