<p>Our system architect left and I'm thrown into a deep water managing Kubernetes cluster.
I'm trying to update ssl-secret on our kubernetes cluster, using the following command</p>
<pre><code>kubectl -n zone-system create secret generic ssl-secret \
        --from-file=./$CERT_FILE \
        --from-file=./$KEY_FILE \
        --dry-run=client \
        -o yaml |
         kubectl apply -f -
</code></pre>
<p>When I run it, however, I get the following error:</p>
<pre><code>error: cannot add key dashboard.yaml, another key by that name already exists
error: no objects passed to apply
</code></pre>
<p>I'm not sure how to resolve it. Tried Google and Stack Overflow searches, but none of the questions are actually related to this error.</p>

igalsc
<p>Make sure you are not passing a duplicate key names <code>dashboard.yaml</code>. you are using two files as input for secrets. <code>CERT_FILE</code> and <code>KEY_FILE</code>, make sure that there is no duplicate key in these two files, specially <code>dashboard.yaml</code>.</p>
<p>To demo the issue, passing a key called <code>dashboard.yaml</code> twice and getting the same error while creating secret. Note that, <code>from-literal</code> is used here for sake of simplicity.</p>
<p>You should <code>grep</code> for <code>&quot;dashboard.yaml&quot;</code> on <code>CERT_FILE</code> and <code>KEY_FILE</code>.</p>
<pre><code>    kubectl create secret generic my-secret --from-literal=dashboard.yaml=supersecret --from-literal=dashboard.yaml=supersecret1
    error: cannot add key dashboard.yaml, another key by that name already exists
</code></pre>
<p>The second error <code>error: no objects passed to apply</code> is because, there is no <code>yaml</code> is generated from <code>dry-run</code>.</p>
<p><strong>Further debugging result:</strong></p>
<p>The <code>echo</code> of your command is returning both the variables <code>CERT_FILE</code> and <code>KEY_FILE</code> as empty and they are both pointing to <code>./</code> leading to duplication.</p>
<pre><code>root@ip-10-10-10-118:/home/code/kubernetes/dev1# echo &quot;kubectl -n zone-system create secret generic ssl-secret --from-file=./$CERT_FILE --from-file=./$KEY_FILE --dry-run=client -o yaml | kubectl apply -f -&quot; 
kubectl -n zone-system create secret generic ssl-secret --from-file=./ --from-file=./ --dry-run=client -o yaml | kubectl apply -f -
</code></pre>
