Skip to content

Helm upgrade fails the release after adding a new resource #6031

Closed

Description

@danie1sullivan

Output of helm version:

Client: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}

Output of kubectl version:

Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.5", GitCommit:"2166946f41b36dea2c4626f90a77706f426cdea2", GitTreeState:"clean", BuildDate:"2019-03-25T15:26:52Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.6-gke.13", GitCommit:"fcbc1d20b6bca1936c0317743055ac75aef608ce", GitTreeState:"clean", BuildDate:"2019-06-19T20:50:07Z", GoVersion:"go1.11.5b4", Compiler:"gc", Platform:"linux/amd64"}

Scenario:

  1. Helm install a chart with resources X, Y, and Z (it doesn't seem to matter which).
  2. Helm upgrade chart to add resource W (in this case a CronJob) - success
$ helm upgrade --install --wait --timeout 600 --namespace myNamespace -f someValues.yaml test .
Release "test" has been upgraded.
LAST DEPLOYED: Wed Jul 17 10:14:58 2019
NAMESPACE: myNamespace
STATUS: DEPLOYED
<snip>
==> v1beta1/CronJob
NAME                          SCHEDULE     SUSPEND  ACTIVE  LAST SCHEDULE  AGE
test-myCron * */1 * * *  False    0       <none>         6s
<snip>
  1. Helm upgrade again, with or without changing anything - failure
$ helm upgrade --install --wait --timeout 600 --namespace myNamespace -f someValues.yaml test .
UPGRADE FAILED
Error: kind CronJob with the name "test-myCron" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
Error: UPGRADE FAILED: kind CronJob with the name "test-myCron" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart

I can delete the CronJob (or whatever resource was added) with kubectl and repeat steps 2 and 3 with the same results. Adding --debug doesn't add anything of value.

It seems related to #1193 but, if I'm reading it correctly, in that issue the deployment would have failed in step 2.

Activity

  1. hickeyma commented on Jul 17, 2019

    @hickeyma
    Contributor

    @goodman-sullivan I tried to reproduce the issue (using the scaffold chart and simple cronjob )but it seems to work OK for me. Here is the output of my investigation. Maybe you could provide more details to help me reproduce it?

    $ helm create chrt-6031
    Creating chrt-6031
    
    $ helm install --name chrt-6031 chrt-6031/
    NAME:   chrt-6031
    LAST DEPLOYED: Wed Jul 17 16:25:54 2019
    NAMESPACE: default
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/Deployment
    NAME       READY  UP-TO-DATE  AVAILABLE  AGE
    chrt-6031  0/1    0           0          1s
    
    ==> v1/Pod(related)
    NAME                       READY  STATUS   RESTARTS  AGE
    chrt-6031-6987788fb-gvwbv  0/1    Pending  0         0s
    
    ==> v1/Service
    NAME       TYPE       CLUSTER-IP    EXTERNAL-IP  PORT(S)  AGE
    chrt-6031  ClusterIP  10.96.111.27  <none>       80/TCP   1s
    
    ==> v1/ServiceAccount
    NAME       SECRETS  AGE
    chrt-6031  1        1s
    
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=chrt-6031,app.kubernetes.io/instance=chrt-6031" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
    
    $ helm ls
    NAME      	REVISION	UPDATED                 	STATUS  	CHART          	APP VERSION	NAMESPACE
    chrt-6031 	1       	Wed Jul 17 16:25:54 2019	DEPLOYED	chrt-6031-0.1.0	1.0        	
    default
    
    $ vim chrt-6031/templates/cronjob.yaml
    
    $ cat chrt-6031/templates/cronjob.yaml
    apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
      name: {{ include "chrt-6031.fullname" . }}
    spec:
      schedule: "*/1 * * * *"
      jobTemplate:
        spec:
          template:
            spec:
              containers:
              - name: hello
                image: busybox
                args:
                - /bin/sh
                - -c
                - date; echo Hello from the Kubernetes cluster
              restartPolicy: OnFailure
    
    $ helm upgrade chrt-6031 chrt-6031/
    Release "chrt-6031" has been upgraded.
    LAST DEPLOYED: Wed Jul 17 16:31:08 2019
    NAMESPACE: default
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/Deployment
    NAME       READY  UP-TO-DATE  AVAILABLE  AGE
    chrt-6031  1/1    1           1          5m14s
    
    ==> v1/Pod(related)
    NAME                       READY  STATUS   RESTARTS  AGE
    chrt-6031-6987788fb-gvwbv  1/1    Running  0         5m13s
    
    ==> v1/Service
    NAME       TYPE       CLUSTER-IP    EXTERNAL-IP  PORT(S)  AGE
    chrt-6031  ClusterIP  10.96.111.27  <none>       80/TCP   5m14s
    
    ==> v1/ServiceAccount
    NAME       SECRETS  AGE
    chrt-6031  1        5m14s
    
    ==> v1beta1/CronJob
    NAME       SCHEDULE     SUSPEND  ACTIVE  LAST SCHEDULE  AGE
    chrt-6031  */1 * * * *  False    0       <none>         0s
    
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=chrt-6031,app.kubernetes.io/instance=chrt-6031" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
    
    $ helm ls
    NAME      	REVISION	UPDATED                 	STATUS  	CHART          	APP VERSION	NAMESPACE
    chrt-6031 	2       	Wed Jul 17 16:31:08 2019	DEPLOYED	chrt-6031-0.1.0	1.0        	default  
    
    $ kubectl get cronjobs
    NAME        SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
    chrt-6031   */1 * * * *   False     0        <none>          35s
    
    $ helm upgrade chrt-6031 chrt-6031/
    Release "chrt-6031" has been upgraded.
    LAST DEPLOYED: Wed Jul 17 16:32:05 2019
    NAMESPACE: default
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/Deployment
    NAME       READY  UP-TO-DATE  AVAILABLE  AGE
    chrt-6031  1/1    1           1          6m10s
    
    ==> v1/Pod(related)
    NAME                       READY  STATUS   RESTARTS  AGE
    chrt-6031-6987788fb-gvwbv  1/1    Running  0         6m9s
    
    ==> v1/Service
    NAME       TYPE       CLUSTER-IP    EXTERNAL-IP  PORT(S)  AGE
    chrt-6031  ClusterIP  10.96.111.27  <none>       80/TCP   6m10s
    
    ==> v1/ServiceAccount
    NAME       SECRETS  AGE
    chrt-6031  1        6m10s
    
    ==> v1beta1/CronJob
    NAME       SCHEDULE     SUSPEND  ACTIVE  LAST SCHEDULE  AGE
    chrt-6031  */1 * * * *  False    1       5s             56s
    
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=chrt-6031,app.kubernetes.io/instance=chrt-6031" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
    
    $ helm ls
    NAME      	REVISION	UPDATED                 	STATUS  	CHART          	APP VERSION	NAMESPACE
    chrt-6031 	3       	Wed Jul 17 16:32:05 2019	DEPLOYED	chrt-6031-0.1.0	1.0        	default  
    
    $ kubectl get cronjobs
    NAME        SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
    chrt-6031   */1 * * * *   False     0        49s             100s
  2. Constantin07 commented on Jul 18, 2019

    @Constantin07

    We are experiencing the same issue but with HPA resource.
    EKS version: 1.11
    Helm version: 2.14.2

    While trying to update the deployment with a new version of chart with added HPA resource, we are getting:

    ...
    helmfile sync
    Building dependency chart
    No requirements found in chart/charts.
    Upgrading chart
    UPGRADE FAILED
    Error: kind HorizontalPodAutoscaler with the name "some_service" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    

    Removing manually the HPA resource and re-running the deployment fixes the situation but is not acceptable for production.

  3. RezzakulHaider commented on Jul 24, 2019

    @RezzakulHaider

    We are also facing the same kind of issue.

    helm upgrade --namespace monitoring -f config.yaml central-monitoring stable/prometheus-operator --version 6.1.1 --force  --debug
    [debug] Created tunnel using local port: 'xxxx'
    
    [debug] SERVER: "127.0.0.1:xxxx"
    
    [debug] Fetched stable/prometheus-operator to /Users/xxxx/.helm/v2.14.1/cache/archive/prometheus-operator-6.1.1.tgz
    
    UPGRADE FAILED
    Error: kind Service with the name "central-monitoring-prometh-kube-proxy" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    Error: UPGRADE FAILED: kind Service with the name "central-monitoring-prometh-kube-proxy" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    

    Even if we delete the service it throws the same error while upgrading.

    We just rolled back to previous successful release.

  4. pv93 commented on Sep 11, 2019

    @pv93

    This is also happening for us with a new HPA resource. I think a useful detail may be that the HPA we are creating is API version autoscaling/v2beta1 while the default version is autoscaling/v1.

  5. den-is commented on Sep 15, 2019

    @den-is

    same here with prometheus-operator on my bare-metal cluster v1.14 which never had any problems and had no recent upgrades

     helm upgrade --install mon \
      --namespace monitoring \
      -f values.yaml \
      stable/prometheus-operator
    UPGRADE FAILED
    Error: kind ConfigMap with the name "mon-prometheus-operator-apiserver" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    Error: UPGRADE FAILED: kind ConfigMap with the name "mon-prometheus-operator-apiserver" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    
  6. Constantin07 commented on Sep 15, 2019

    @Constantin07

    Does anyone have an idea of the nature/root cause of these errors ?
    Unfortunately, I don't have good knowledge of Go language to dig it myself.

    It just makes impossible to use helm in production.

  7. bacongobbler commented on Sep 15, 2019

    @bacongobbler
    Member

    That error indicates that you introduced a new resource into the chart, but that resource already existed in the cluster. Helm does not "adopt" existing resources; if a resource exists before it was introduced in the chart, it's considered an error condition, hence the error message.

    To fix this, remove the resource from the cluster using kubectl delete, then call helm upgrade again.

  8. bacongobbler commented on Sep 15, 2019

    @bacongobbler
    Member

    See also #3275.

  9. den-is commented on Sep 15, 2019

    @den-is

    @bacongobbler i have not done super deep inspection. but this is not case.
    and somehow i'm not only one who has problem with prometheus-operator specifically.
    I'm deleting all resources it is asking. It just never stops saying about existant/non-existant resources.
    I update this chart almost instantly. and latest update has no huge changes in chart structure
    https://github.com/helm/charts/tree/0459eb2bdade42a88a44ee115184ba584bd3131c (pinned to problematic commit)

    i will definitely try to inspect yaml closely.

    But for now rollback has worked just fine.

  10. bacongobbler commented on Sep 15, 2019

    @bacongobbler
    Member

    The next time you encounter the error message, can you please show the output of kubectl get all in the namespace you're attempting to deploy as well as the error message you're seeing? Thanks.

  11. fernandoalex commented on Sep 15, 2019

    @fernandoalex

    @bacongobbler the problem is that we did not add any resources. It's like helm lost track of a resource it created. Removing the resource it is complaining about does solve the issue for the next run, but after some time the problem starts again.

  12. Constantin07 commented on Sep 16, 2019

    @Constantin07

    @bacongobbler I second @fernandoalex - I'm 100% sure that no new resources for chart had been added manually or by any other means in the cluster before the update the chart.

    And it's not related to specific resource type - in one case it failed when we added an HPA, in another a config map.

    Given the fact that helm is quite spread and widely used in Kubernetes ecoystem as deployment tool, I don't understand how people are using it in production ...

    Is it suppose to work like that ? break sporadically and require manual intervention to delete custom resources ...

  13. mjhuber commented on Sep 18, 2019

    @mjhuber

    I'm seeing this issue too.
    Step 1> Deploy chart with new CronJob objects added (don't yet exist in cluster). Deploy is successful.
    Step 2> Next deploy fails with error:

    Error: UPGRADE FAILED: kind CronJob with the name "staging-sitemap-cron-job" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    Detected that there are existing resources.
    

    The only workaround we have found is to run helm del --purge on the release and re-deploy. We are using helm v2.14.3.

  14. elpadrinoIV commented on Sep 20, 2019

    @elpadrinoIV

    I had this issue more than once, but this time I found something in common.
    It may have to do when you change subcharts version and (this part I don't remember quite well) the upgrade fails for some reason.
    From that point, you'll run over this problem again and again.
    Hope this helps!

  15. 7 remaining items

  16. morganchristiansson commented on Oct 21, 2019

    @morganchristiansson

    Just had this happein in one out of 3 deployments following adding configmap. rollback per @hoffoo works.

  17. macrozone commented on Oct 28, 2019

    @macrozone

    "--cleanup-on-fail" does not help. Failed upgrades still does not remove helm-hook-jobs. So the next upgrade will yield: Error: UPGRADE FAILED: jobs.batch "my-helm-hook-job" already exists

  18. pc-rshetty commented on Nov 7, 2019

    @pc-rshetty

    We are facing same issue while upgrading istio .

    
    
    STDERR:
    
    Error: UPGRADE FAILED: kind PodDisruptionBudget with the name "istio-sidecar-injector" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    
    
    MSG:```
    
  19. pc-rshetty commented on Nov 7, 2019

    @pc-rshetty

    our helm version is 2.14.3

  20. erenatas commented on Nov 11, 2019

    @erenatas

    our helm version is 2.14.3

    I am experiencing this problem as well.

    UPGRADE FAILED
    Error: kind Service with the name "XXXXXXXXXXXX" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart
    

    Edit:
    Ok so I have found a temporary solution (which may not work for everyone) but at least it's better than doing a '''helm delete --purge''' which will delete all of your data. You can do:

    helm rollback <release-name> 0
    

    to rollback to the previous revision of your helm deployment and then do a:

    helm upgrade <release-name> .
    

    This worked for me.

  21. heisend4rk commented on Dec 6, 2019

    @heisend4rk

    Ah, i finally understood why this error repeats even when we delete the service account.
    What really happens is when you apply your file with

    helm upgrade -f

    He assigns the first service account without any problem, that whyit takes some delay to respond, then he moves to assign the next one but surprise, here k8S finds that the service account is already there, so to fix this, simply don't declare your service account more than once in your values.yaml file (this is only for my case).

  22. cristiklein commented on Jan 1, 2020

    @cristiklein

    This seems to be caused by Tiller's database getting corrupted. For example, on one of my clusters:

    $ kubectl get cm -n kube-system -l OWNER=TILLER,STATUS=DEPLOYED 
    NAME                       DATA   AGE
    foo.v4                     1      8m12s
    bar.v206   1      8h
    bar.v207   1      8h
    bar.v99    1      33d
    

    In other words, Tiller's internals might take either v99, v206 or v207 as the DEPLOYED version, which leads to the error above.

    I ended up (brutally) deleting the extra CMs: kubectl delete -n kube-system cm bar.v99.

  23. added 2 commits that reference this issue on Jan 1, 2020
    03853ae
    840e0e2
  24. jason-liew commented on Jan 8, 2020

    @jason-liew
  25. bacongobbler commented on Jan 8, 2020

    @bacongobbler
    Member

    closed with #7319.

  26. thedodd commented on Feb 5, 2020

    @thedodd

    For anyone coming to this issue in the future. I can confirm that Tiller is indeed the culprit, at least for many of the cases we've run into matching this issue's description. The fix is described above: #6031 (comment) thanks @cristiklein

  27. cristiklein commented on Feb 6, 2020

    @cristiklein

    @thedodd Now there should be a fix in Tiller master. helm init --canary-image

  28. added a commit that references this issue on Mar 23, 2020
    0c99ca7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions