<p>I have a deployment config for an app, that (among other things) creates a secret for a mysql database:</p>

<pre><code>---
apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  MYSQL_USER: my_user
  MYSQL_PASSWORD: my_random_secret
  MYSQL_DATABASE: my_db
  MYSQL_ROOT_PASSWORD: my_random_secret
---
etc...
</code></pre>

<p>The deployment file is under source control, so I don't want to place the secrets there.</p>

<p>Does anyone know how I can tell Kubernetes to generate random strings for each variable which has <code>my_random_secret</code> as a value in my example? Preferably something that can be configured using the yaml file, without needing to invoke any extra commands.</p>

<p>As far I have understood that you do not want to keep your secret information locally. So that you need to generate them when you are creating that secret.</p>

<p>I think there is a way to create Kubernetes resource using go-template. Didn't find enough information for that. I can't help you in this way.</p>

<p>But you can also create secret using script. And your secret will not be exposed.</p>

<p>Following script can help you in that case. This will generate random password for you and will create secret with that.</p>

<pre><code>cat &lt;&lt;EOF | kubectl create -f -
apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  MYSQL_PASSWORD: $(head -c 24 /dev/random | base64)
  MYSQL_ROOT_PASSWORD: $(head -c 24 /dev/random | base64)
stringData:
  MYSQL_USER: my_user
  MYSQL_DATABASE: my_db
EOF
</code></pre>

<p>Run this script.</p>

<p>Hope  it will work for you</p>
