<p>I've deploed an app to k8s using <code>kubectl apply ...</code> few weeks ago, the application is <strong>running in prod.</strong>
Now we switch to helm installation and build chart that we want to update the application with it.
The problem is that there is already deployed artifacts like secret/config maps of the application
<strong>which I cannot delete</strong>.</p>
<p>And while running <code>helm upgrade --install app chart/myapp -n ns </code></p>
<p><strong>I got error like</strong></p>
<blockquote>
<p>Error: rendered manifests contain a resource that already exists.
Unable to continue with install: existing resource conflict:
namespace: ns, name: bts, existing_kind: /v1, Kind=Secret, new_kind:
/v1, Kind=Secret</p>
</blockquote>
<p>Is there any <strong>trick</strong> which I can use to <strong>overcome this without deleting</strong> the secret/configmap ?</p>

<p>After testing some options in my lab, I've realized that the way I told you in comments worked.</p>
<p>Helm uses information on <code>metadata</code> and <code>labels</code> are injected in the resources to know what are the resources managed by itself.  The <strong>workaround</strong> below shows how you can <em>import</em> a previous created secret, not managed by Helm, using <code>matadata</code> information from a new secret deployed with Helm.</p>
<p>Let's suppose the <code>my-secret</code> is already deployed and you want to <em>&quot;import&quot;</em> that resource to helm, you need to get the metadata information of the new resource.  Let's dig into it:</p>
<p><strong>Scenario:</strong></p>
<ol>
<li>A <code>secret</code>  name <code>my-secret</code> deployed in <code>default</code> name space. (Not managed by Helm)</li>
<li>A helm chart with a secret template named <code>my-new-var</code> with a different value.</li>
</ol>
<p><strong>Steps:</strong></p>
<ol>
<li>Create a normal secret for testing purposes using this spec:</li>
</ol>
<pre><code>    apiVersion: v1
    kind: Secret
    metadata:
      name: my-secret
    type: Opaque
    data:
      secret: S29vcGFLaWxsZXIK
</code></pre>
<ol start="2">
<li>Apply the Helm chart to create the <code>my-new-secret</code>. The real purpose of that is get the <code>metadata</code> and <code>labels</code> information.</li>
</ol>
<p>After that you can see the secret file using the command:</p>
<p><code>kubectl get secrets my-secret -o yaml</code>:</p>
<pre><code>apiVersion: v1
data:
  secret: VXB2b3RlSXQ=
kind: Secret
metadata:
  annotations:
    meta.helm.sh/release-name: myapp-1599472603
    meta.helm.sh/release-namespace: default
  creationTimestamp: &quot;2020-09-07T10:03:05Z&quot;
  labels:
    app.kubernetes.io/managed-by: Helm
  name: my-secret
  namespace: default
  resourceVersion: &quot;2064792&quot;
  selfLink: /api/v1/namespaces/default/secrets/my-secret
  uid: 7cf66475-b26b-415b-8c11-8fb6974da495
type: Opaque
</code></pre>
<p>From this file we need to get the <code>annotations</code> and <code>labels</code> to apply in our old <code>my-secret</code>.</p>
<ol start="3">
<li>Edit the secret file created on step 1 to add thoses information. It will result in a file like that:</li>
</ol>
<pre><code>apiVersion: v1
data:
  secret: S29vcGFLaWxsZXIK
kind: Secret
metadata:
  annotations:
    meta.helm.sh/release-name: myapp-1599472603
    meta.helm.sh/release-namespace: default
  name: my-secret
  labels:
    app.kubernetes.io/managed-by: Helm
  namespace: default
</code></pre>
<ol start="4">
<li><p>Delete the <code>my-new-secret</code> create by Helm, since we not longer use it:
<code>kubectl delete secrets my-new-secret</code></p>
</li>
<li><p>In the Helm chart, edit the secret name to match with the old secret, in our case change the name from <code>my-new-secret</code> to <code>my-secret</code>.</p>
</li>
<li><p>Upgrade the Helm chart, in my case I have used a value from Values.yaml:</p>
</li>
</ol>
<pre><code>$ helm upgrade -f myapp/values.yaml myapp-1599472603 ./myapp/
Release &quot;myapp-1599472603&quot; has been upgraded. Happy Helming!
NAME: myapp-1599472603
LAST DEPLOYED: Mon Sep  7 10:28:38 2020
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
</code></pre>
