<p>how to persist the parameter key values to values.yaml file while use command line to set the values.helm install . --name test --set image.tag=2020 --set image.version=20 how to update this image.tag and image.version values to values.yaml? dry run will give the result but wont update the values.yaml</p>

<p><strong>Helm</strong> is a package manager, and it's all about automating deployment of kubernetes apps. It's designed to be somewhat static, and only being changed by the creator of the chart.</p>

<ul>
<li><p><a href="https://helm.sh/docs/chart_template_guide/values_files/" rel="nofollow noreferrer">Values Files</a> provides access to values passed into the chart. Its contents come from multiple sources:</p>

<blockquote>
  <ul>
  <li>The <code>values.yaml</code> file <strong>in the chart</strong></li>
  <li>If this is a subchart, the <code>values.yaml</code> file <strong>of a parent chart</strong></li>
  <li><strong>A values file if passed into helm install</strong> or helm upgrade with the <code>-f</code> flag (<code>helm install -f myvals.yaml ./mychart</code>)</li>
  <li><strong>Individual parameters</strong> passed with <code>--set</code> (such as <code>helm install --set foo=bar ./mychart</code>)</li>
  </ul>
</blockquote></li>
<li><p>This is the base Hierarchy of the values files, but there is more to it:</p></li>
</ul>

<p><a href="https://i.stack.imgur.com/BsGIk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BsGIk.png" alt="enter image description here"></a>
<em>Kudos to the creator of this image, unfortunately I wasn't able to find the author to credit him.</em></p>

<ul>
<li>You can't change the chart <code>values.yaml</code> file exacly as you are thinking, because the original <code>values.yaml</code> will keep the state desired by the creator of the chart.</li>
<li>The flowchart above is all about changes made during <code>helm install</code> or <code>helm upgrade</code>.</li>
</ul>

<hr>

<p>I'll try to exemplify your use scenario:</p>

<ul>
<li>Chart 1 has the default values with:</li>
</ul>

<pre><code>image: original-image
version: original-version
</code></pre>

<ul>
<li>You decided to deploy this chart changing some values using <code>--set</code> as in your example <code>helm install --name abc --set image=abc --set version-123</code>. Resulting in:</li>
</ul>

<pre><code>image: abc
version: 123
</code></pre>

<ul>
<li>Then you want to upgrade the chart and modify the <code>version</code> value but keeping the other values as set, you run: `helm upgrade --set version=124 --reuse-values, here is the result values in effect:</li>
</ul>

<pre><code>image: abc
version: 124
</code></pre>

<p><strong>NOTE:</strong> As we seen in the flowchart, <strong>if you don't specify --reuse-values</strong> it will reset the values that were not <code>--set</code> during the upgrade to back to the original of the chart. In this case <code>image</code> would again be <code>original-image</code>.</p>

<hr>

<p>So, to wrap up your main question:</p>

<blockquote>
  <p>how to persist --set key values to values.yaml in helm install/upgrade?</p>
</blockquote>

<p>You can persist the <code>--set</code> values during the <code>upgrade</code> by always using <code>--reuse-values</code>, however the changes will never be commited to the original template of <code>values.yaml</code> file.</p>

<p>If you are the owner of the chart, It's the recommended behavior that you create release versions of your chart, so you can keep track of what were the default in each version.</p>

<p>I hope it helps clarifying the issue.</p>

<p>If I can help you any further, let me know in the comments.</p>
