<p>How to deploy the helm release for the first time when there's already the deployment, svc, etc. running with the same name.</p>
<p>Is there's any way to import the config running, which is not being handled by helm?</p>
<p>Or deleting the same name objects is the only solution to deploy the helm release first time?(As I don't want to change the release names because it will break the communication between the microservices)
Deleting the objects will cause downtime and I want to avoid that.</p>
<p>Error getting while deploying with the same name:</p>
<pre><code>Error: rendered manifests contain a resource that already exists. Unable to continue with install: Service &quot;abc&quot; in namespace &quot;default&quot; exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key &quot;app.kubernetes.io/managed-by&quot;: must be set to &quot;Helm&quot;; annotation validation error: missing key &quot;meta.helm.sh/release-name&quot;: must be set to &quot;abc&quot;; annotation validation error: missing key &quot;meta.helm.sh/release-namespace&quot;: must be set to &quot;default&quot;
</code></pre>
<p>Is their any other approach?</p>
<p>Thanks</p>

<p>Addressing the error message and part of the question:</p>
<blockquote>
<p>How to deploy the helm release for the first time when there's already the deployment, svc, etc. running with the same name.</p>
</blockquote>
<p>You can't deploy resources with Helm that weren't created by Helm. It will give you the same message as you've encountered. You can annotate the existing resources that <strong>were not</strong> added by Helm to &quot;import&quot; the existing resources and act on them. <strong>Please try to run your workload on a test environment first before trying it as it could redeploy some resources.</strong></p>
<p>There is already similar answer on how to annotate resources:</p>
<ul>
<li><em><a href="https://stackoverflow.com/a/62528643/12257134">Stackoverflow.com: Answers: Use Helm 3 for existing resources deployed with kubectl</a></em></li>
</ul>
<blockquote>
<p>see this feature of helm3 <a href="https://github.com/helm/helm/pull/7649" rel="noreferrer">Adopt resources into release with correct instance and managed-by labels</a></p>
<p>Helm will no longer error when attempting to create a resource that already exists in the target cluster if the existing resource has the correct meta.helm.sh/release-name and meta.helm.sh/release-namespace annotations, and matches the label selector app.kubernetes.io/managed-by=Helm. This facilitates zero-downtime migrations to Helm 3 for managing existing deployments, and allows Helm to &quot;adopt&quot; existing resources that it previously created.</p>
<p>In order to allow an existing resource to be adopted by Helm, add release metadata and the managed-by label:</p>
<pre><code>KIND=deployment
NAME=my-app-staging
RELEASE=staging
NAMESPACE=default
kubectl annotate $KIND $NAME meta.helm.sh/release-name=$RELEASE
kubectl annotate $KIND $NAME meta.helm.sh/release-namespace=$NAMESPACE
kubectl label $KIND $NAME app.kubernetes.io/managed-by=Helm
</code></pre>
</blockquote>
<hr />
<p>Assuming following situation:</p>
<ul>
<li><code>Deployment</code> created outside of Helm (example below).</li>
<li>Helm Chart with equivalent templated <code>Deployment</code> in <code>templates/</code> (example below).</li>
</ul>
<p>Creating below <code>Deployment</code> without Helm:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
</code></pre>
<p>Assuming that above file is used with <code>kubectl apply</code> and it's also residing in <code>templates/</code> directory (templated) of your Chart, you will get the following error (when you try to run  <code>$ helm install release_name .</code>):</p>
<pre><code>Error: rendered manifests contain a resource that already exists. Unable to continue with install: Deployment &quot;nginx&quot; in namespace &quot;default&quot; exists and cannot be imported into the current release: ... 
</code></pre>
<p>By running the script that was mentioned in the answer I linked, you can annotate and label your resources for Helm to not produce mentioned error message.</p>
<p>After that you can run <code>$ helm install release_name .</code> and provision your resources with desired changes.</p>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://jacky-jiang.medium.com/import-existing-resources-in-helm-3-e27db11fd467" rel="noreferrer">Jacky-jiang.medium.com: Import existing resources in Helm3</a></em></li>
</ul>
