<p>With the following command: <code>kubectl -n ns create secret generic test2 --from-literal=username=xxxxxx</code> I am able to create secrets. I would like to find a way (programmatically) to use a list instead of using literal=username=xxxxxx because sometimes I need more than one literal.</p>
<p>What I tried is the following:</p>
<pre><code>NS=test-ns
SF=secrets.yaml
unset SECRET_NAMES
value+=(username)
value+=(password)
echo &quot;&quot; &gt; $SF
for value in &quot;${value[@]}&quot;
do
        kubectl -n ${NS} create secret generic test2 \
                --from-literal=$value=xxxxxx \
                -o yaml &gt;${NS}-$secret_name.yaml
done
cat $SF
</code></pre>
<p>but it failed because it creates first the username and then it not able to create the password because the secret test2 is already exits. Do you have any idea how can I solve this issue?</p>

Angel
<p>You can repeat the <code>--from-literal</code> flag as many times as you want:</p>
<pre><code>$ kubectl create secret generic test2 --from-literal=username=xxxxxx --from-literal=username2=xxxxxx
secret/test2 created

$ kubectl get secrets test2 -oyaml
apiVersion: v1
type: Opaque
kind: Secret
metadata:
  name: test2
data:
  username: eHh4eHh4
  username2: eHh4eHh4
</code></pre>
