<p>I have the following <code>secrets.yaml</code> in <code>templetes</code> in Helm Charts:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  USER_NAME: YWRtaW4=
  PASSWORD: MWYyZDFlMmU2N2Rm 
</code></pre>
<p>I need to create the same secret in different namespace, for example, namespace <code>test1</code>, <code>test2</code>, <code>test3</code>, <code>test4</code>, how to specify the different namespace with the same <code>secrets</code> so the same <code>secret</code> can be created in different namespace?</p>

<p>You can set the namespace name in the <code>metadata</code> section like</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
  namespace: test1
type: Opaque
data:
  USER_NAME: YWRtaW4=
  PASSWORD: MWYyZDFlMmU2N2Rm
</code></pre>
<p>You can set a for loop with helm to create one <code>Secret</code> definition in each namespace.</p>
<p>Update.</p>
<pre class="lang-yaml prettyprint-override"><code># values.yaml
namespaces:
  - test1
  - test2

# templates.secrets.tpl
{{- range .Values.namespaces }}
---
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
  namespace: {{ . | quote }}
type: Opaque
data:
  USER_NAME: YWRtaW4=
  PASSWORD: MWYyZDFlMmU2N2Rm

{{- end }}


### output ###
---
# Source: base/templates/secrets.tpl

---
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
  namespace: &quot;test1&quot;
type: Opaque
data:
  USER_NAME: YWRtaW4=
  PASSWORD: MWYyZDFlMmU2N2Rm
---
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
  namespace: &quot;test2&quot;
type: Opaque
data:
  USER_NAME: YWRtaW4=
  PASSWORD: MWYyZDFlMmU2N2Rm
</code></pre>
