I'm using Jenkins X for microservice build / deployment. In each environment there are shared secrets used across microservices (client keys etc) which are injected into deployment.yaml
as environment variables using valueFrom
and secretKeyRef
. This works well in Production and Staging where the namespaces are well know, but since preview generates a new namespace each time, these secrets will no exist. Is there a way to copy secrets from another, known, namespace, or a better approach?

- 155
- 9
3 Answers
You can create another namespace called jx-preview
to store preview specific secrets, and add this line after the jx preview
command in your Jenkinsfile
sh "kubectl get secret {secret_name} --namespace={from_namespace} --export -o yaml | kubectl apply --namespace=jx-$ORG-$PREVIEW_NAMESPACE -f -"
Not sure if this is the best way though

- 819
- 8
- 8
We've got a command to service link services from one namespace to another - such as to link services from staging to your preview environment via jx step link services.
It would be nice to add a similar command to copy secrets from a namespace in the same way. I've raised an issue to track this new feature

- 9,168
- 34
- 31
Another option is to create your own Job in charts/preview/templates/myjob.yaml
and in that job create whatever Secrets you need however you want and then annotate it so that its triggered as a post-install hook of your Preview chart

- 9,168
- 34
- 31