<p>We have Helm 3.0.3 and 1.18 k8s and since one year we did not face any issue like as below before. We deploy several microservices via helm to k8s and all works fine so far. But even if we did not change anything for service field we are receiving error like as below.</p>
<p>Here is my command how I deploy to k8s. When I uninstall the service in k8s and start re-build it works ok but when I need to push new changes ı again face this error.</p>
<pre><code>+ helm upgrade --install --debug --force xx-ui-dev --values values.dev.yaml --namespace dev --set image.tag=608 .
</code></pre>
<hr />
<p>Error</p>
<pre><code>history.go:52: [debug] getting history for release xx-ui-dev
upgrade.go:120: [debug] preparing upgrade for xx-ui-dev
upgrade.go:128: [debug] performing update for xx-ui-dev
upgrade.go:292: [debug] creating upgraded release for xx-ui-dev
client.go:173: [debug] checking 7 resources for changes
client.go:432: [debug] Replaced &quot;xx-ui-dev&quot; with kind NetworkPolicy for kind NetworkPolicy

client.go:432: [debug] Replaced &quot;xx-ui-dev&quot; with kind ServiceAccount for kind ServiceAccount

client.go:432: [debug] Replaced &quot;xx-ui-dev-auth&quot; with kind Secret for kind Secret

client.go:432: [debug] Replaced &quot;xx-ui-dev-config&quot; with kind ConfigMap for kind ConfigMap

client.go:205: [debug] error updating the resource &quot;xx-ui-dev&quot;:
     failed to replace object: Service &quot;xx-ui-dev&quot; is invalid: spec.clusterIP: Invalid value: &quot;&quot;: field is immutable
client.go:432: [debug] Replaced &quot;xx-ui-dev&quot; with kind Deployment for kind Deployment

client.go:432: [debug] Replaced &quot;xx-ui-dev&quot; with kind HorizontalPodAutoscaler for kind HorizontalPodAutoscaler

upgrade.go:351: [debug] warning: Upgrade &quot;xx-ui-dev&quot; failed: failed to replace object: Service &quot;xx-ui-dev&quot; is invalid: spec.clusterIP: Invalid value: &quot;&quot;: field is immutable
Error: UPGRADE FAILED: failed to replace object: Service &quot;xx-ui-dev&quot; is invalid: spec.clusterIP: Invalid value: &quot;&quot;: field is immutable
helm.go:84: [debug] failed to replace object: Service &quot;xx-ui-dev&quot; is invalid: spec.clusterIP: Invalid value: &quot;&quot;: field is immutable
</code></pre>
<hr />
<p>service.yaml</p>
<pre><code>    spec:
      type: {{ .Values.service.type }}
      ports:
        - port: {{ .Values.service.port }}
          targetPort: 50003
          protocol: TCP
          name: http
      selector:
        app.kubernetes.io/name: {{ include &quot;xx-ui.name&quot; . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        tier: backend
</code></pre>
<hr />
<pre><code>values.dev.yaml

   service:
     type: ClusterIP
     port: 80
</code></pre>

<p>When using <code>--force</code> with <code>helm upgrade</code>, helm is using replace strategy instead of patch.</p>
<p>Have a look at the following <a href="https://github.com/helm/helm/blob/master/pkg/kube/client.go#L423-L450" rel="noreferrer">helm code</a>:</p>
<pre><code>if force {
    var err error
    obj, err = helper.Replace(target.Namespace, target.Name, true, target.Object)
        
    ...

} else {
    patch, patchType, err := createPatch(target, currentObj)

    ...

    // send patch to server
    obj, err = helper.Patch(target.Namespace, target.Name, patchType, patch, nil)
}
</code></pre>
<p>Replace strategy is causing the errors you see.
Have a look at <a href="https://github.com/kubernetes/kubectl/issues/798" rel="noreferrer">this kubectl issue</a> if you are wondering why this happens.</p>
