K8s: deployment valueFrom
secretKeyRef optional if the secret is not present
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.