You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
helm rollback with service modification results in inconsistent state #3675
After helm rollback (see repro steps below) failed with
Error: Service "" is invalid: spec.ports[0].nodePort: Invalid value: 30849: may not be used when `type` is 'ClusterIP'
Then another helm rollback --force results in
Error: "[release name]" has no deployed releases
The release resulted in a limbo such that helm upgrade cannot find the release and helm install results in
Error: a release named [release name] already exist
Repro steps:
$ helm create chart01
$ helm install --name chart01rel ./chart01
$ # change service.type from ClusterIP to LoadBalancer
$ helm upgrade chart01rel ./chart01
$ # wait for load balancer to get provisioned
$ helm rollback chart01rel 1 --dry-run
Rollback was a success! Happy Helming!
$ helm rollback chart01rel 1
Error: Service "[release name]" is invalid: spec.ports[0].nodePort: Invalid value: 30849: may not be used when `type` is 'ClusterIP'
It appears to be the case that Kubernetes is assigning a nodePort to the Service when you change the type from ClusterIP to LoadBalancer. But this is not a valid value for a ClusterIP. So when you roll back, it generates an error when Kubernetes merges the rollback manifest into the running service.
Note that it is Kubernetes, not Helm, that is automatically adding the nodePort value. It looks like a chart would have to expose nodePort on the service as a configurable parameter so that it could be overridden in cases like this.
The problem is that helm gets stuck with the pending update. If you run a helm rollback with ‘—force’, it works, but if you don’t the rollback is stuck and the deployment disappears from ‘helm ls’.
I forgot to say: It is NOT a question, this is a bug, because we are expecting helm to handle the rollback. It may cause outages due to the fact that we can't rollback again.
So if we deploy something with ClusterIP, then we switch to LoadBalancer by mistake and we want to rollback, we will meet this error (if we don't use --force)... then helm is stuck! If we trigger a second rollback, maybe with --force this time to "fix" the ClusterIPnodePort, all the rollbacks will be "pending", but if we run helm ls the deployment will not be there. We can't do anymore a helm install and we can't do a helm delete
I've just run through the repro steps above and captured a few extra outputs...
(The chart below is just the output of helm create test)
Install with ClusterIP ~/go/src/k8s.io/helm/bin/helm install --name test ./test --set service.type=ClusterIP
Upgrade to use LoadBalancer ~/go/src/k8s.io/helm/bin/helm upgrade test ./test --set service.type=LoadBalancer
History:
$ ~/go/src/k8s.io/helm/bin/helm history test
REVISION UPDATED STATUS CHART DESCRIPTION
1 Thu Mar 15 10:21:51 2018 SUPERSEDED test-0.1.0 Install complete
2 Thu Mar 15 10:23:52 2018 DEPLOYED test-0.1.0 Upgrade complete
Rollback to version 1 (ClusterIP) ~/go/src/k8s.io/helm/bin/helm rollback test 1
Error: rpc error: code = Unknown desc = Service "test" is invalid: spec.ports[0].nodePort: Invalid value: 32644: may not be used when `type` is 'ClusterIP'
$ ~/go/src/k8s.io/helm/bin/helm history test
REVISION UPDATED STATUS CHART DESCRIPTION
1 Thu Mar 15 10:21:51 2018 SUPERSEDED test-0.1.0 Install complete
2 Thu Mar 15 10:23:52 2018 SUPERSEDED test-0.1.0 Upgrade complete
3 Thu Mar 15 10:25:14 2018 PENDING_ROLLBACK test-0.1.0 Rollback to 1
Note that the history shows PENDING_ROLLBACK for the failed rollback. In the tiller logs:
[tiller] 2018/03/15 10:25:15 warning: Failed to record release test: release: "test.v3" already exists
At this point helm ls returns no entries
helm install returns
Error: rpc error: code = Unknown desc = a release named test already exists.
Run: helm ls --all test; to check the status of the release
Or run: helm del --purge test; to delete it
helm rollback --force
Error: rpc error: code = Unknown desc = "test" has no deployed releases
helm upgrade
Error: UPGRADE FAILED: rpc error: code = Unknown desc = "test" has no deployed releases
After looking into the tiller error, I noticed that this line has s.recordRelease(targetRelease, false). The false tells recordRelease to try to create the release record but it has already been created by prepareRollback with the PENDING_ROLLBACK status. I changed this line to s.recordRelease(targetRelease, true) and re-tested, and the tiller failed to record release error no longer occurred.
With this change in place, the history after the failed rollback becomes
REVISION UPDATED STATUS CHART DESCRIPTION
1 Thu Mar 15 11:11:10 2018 SUPERSEDED test-0.1.0 Install complete
2 Thu Mar 15 11:11:16 2018 SUPERSEDED test-0.1.0 Upgrade complete
3 Thu Mar 15 11:11:21 2018 FAILED test-0.1.0 Rollback "test" failed: Service "test" is invalid: spec.p...
However, helm install and helm upgrade both still fail as before.
I've tried to reproduce the issue using kubectl apply and got the same issue. So I think the analysis from @technosophos is right here, you should expose nodePort in the helm chart explicitly and set it to 0 for the service of type ClusterIP.
I0331 16:56:29.063604 31838 request.go:873] Request Body: {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"pgsql\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"name\":\"postgres\",\"port\":5432,\"protocol\":\"TCP\",\"targetPort\":5432}],\"selector\":{\"app\":\"pm-postgres\"},\"type\":\"ClusterIP\"}}\n"}},"spec":{"type":"ClusterIP"}}
I0331 16:56:29.063655 31838 round_trippers.go:417] curl -k -v -XPATCH -H "Accept: application/json" -H "Content-Type: application/strategic-merge-patch+json" -H "User-Agent: kubectl/v1.9.4 (darwin/amd64) kubernetes/bee2d15" https://192.168.99.100:8443/api/v1/namespaces/default/services/pgsql
I0331 16:56:29.065930 31838 round_trippers.go:436] PATCH https://192.168.99.100:8443/api/v1/namespaces/default/services/pgsql 422 Unprocessable Entity in 2 milliseconds
I0331 16:56:29.065958 31838 round_trippers.go:442] Response Headers:
I0331 16:56:29.065965 31838 round_trippers.go:445] Content-Type: application/json
I0331 16:56:29.065972 31838 round_trippers.go:445] Content-Length: 426
I0331 16:56:29.065978 31838 round_trippers.go:445] Date: Sat, 31 Mar 2018 12:56:29 GMT
I0331 16:56:29.066011 31838 request.go:873] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Service \"pgsql\" is invalid: spec.ports[0].nodePort: Invalid value: 32535: may not be used when `type` is 'ClusterIP'","reason":"Invalid","details":{"name":"pgsql","kind":"Service","causes":[{"reason":"FieldValueInvalid","message":"Invalid value: 32535: may not be used when `type` is 'ClusterIP'","field":"spec.ports[0].nodePort"}]},"code":422}
F0331 16:56:29.066306 31838 helpers.go:119] The Service "pgsql" is invalid: spec.ports[0].nodePort: Invalid value: 32535: may not be used when `type` is 'ClusterIP'
Second attempt where the port definition has nodePort set to 0:
The underlying issue here is that we tried to transition from ClusterIP -> LoadBalancer -> ClusterIP, and the second transition failed because nodePort was configured by LoadBalancer and is invalid for ClusterIP. The comment from @zaa is useful thinking about this going forwards for this particular case.
However, in terms of the state of the release in helm I believe that there is an underlying issue with helm: we got to a situation that we could only recover from with helm delete and starting over.
I recently spent some time digging into this with @technosophos and have done some more research since that I'd like to add to the thread for discussion.
In the case of this issue, we arrived at the "no way forward" situation by doing the LoadBalancer -> ClusterIP transition as a rollback. I figured that it should be possible to do that transition as an upgrade and expected to reach the same "no way forward" situation with helm.... but I didn't!
Doing this as a rollback I ended up with:
REVISION UPDATED STATUS CHART DESCRIPTION
1 Thu May 3 15:57:13 2018 SUPERSEDED helm-test-0.1.0 Install complete
2 Thu May 3 15:57:16 2018 SUPERSEDED helm-test-0.1.0 Upgrade complete
3 Thu May 3 15:57:18 2018 FAILED helm-test-0.1.0 Rollback "failed-rollback" failed: Service "failed-rollba...
And at this point neither upgrade nor rollback will allow you to proceed.
However, with upgrade I ended up with:
REVISION UPDATED STATUS CHART DESCRIPTION
1 Thu May 3 15:59:25 2018 SUPERSEDED helm-test-0.1.0 Install complete
2 Thu May 3 15:59:27 2018 DEPLOYED helm-test-0.1.0 Upgrade complete
3 Thu May 3 15:59:29 2018 FAILED helm-test-0.1.0 Upgrade "failed-upgrade" failed: Service "failed-upgrade-...
The key difference here is that we still have a revision marked as deployed.
So for a failed upgrade the previous release is left as DEPLOYED whereas for a failed rollback the previous release is marked as SUPERSEDED.
Looking back in history, I first found #1137 that discusses this behaviour and seems to suggest that the current rollback behaviour is expected. There are two PRs referenced from the issue that add in the SUPERSEDED behaviour (tagging @michelleN as the contributor of those PRs :-)). Looking back in the code logs, I then found this change that reversed the behaviour as part of fixing #2437
At this point I'm confused as to what the behaviour should be!
What should be the behaviour for rollback/upgrade in terms of whether they leave the previously revision as DEPLOYED vs SUPERSEDED on failure?
I paired with @technosophos on this and found two issues beings discussed in this thread.
The first one is a bug that was introduced in the refactor on kubernetes v1.10 that no longer validated objects against a schema. Fixed now in #4042. This should capture all the examples listed in the issue.
The second issue is how we handle releases in a failed state. When a failure occurs during a release some resources could be deployed/patched/deleted/created and in a broken state. To calculate a patch to rollback is difficult because we don't know the full state of the cluster anymore. We make assumptions that try to get it close. For helm 3 I am looking at ways we can implement a proper reconcile against cluster resources.
Given that we have the fix for this in #4042 and are planning to further address this reconciliation with our Helm 3 design, should we go ahead and close out this issue? Or would you prefer to keep it open to validate the Helm 3 design against?
Thanks everyone for chiming in and fixing this bug!!! 👏 If it's ok with everyone, let's keep this issue open so we can validate how we handle releases in a failed state against Helm 3.
Activity
technosophos commentedon Mar 14, 2018
It appears to be the case that Kubernetes is assigning a nodePort to the Service when you change the type from ClusterIP to LoadBalancer. But this is not a valid value for a ClusterIP. So when you roll back, it generates an error when Kubernetes merges the rollback manifest into the running service.
Note that it is Kubernetes, not Helm, that is automatically adding the nodePort value. It looks like a chart would have to expose
nodePorton the service as a configurable parameter so that it could be overridden in cases like this.koalalorenzo commentedon Mar 14, 2018
The problem is that helm gets stuck with the pending update. If you run a helm rollback with ‘—force’, it works, but if you don’t the rollback is stuck and the deployment disappears from ‘helm ls’.
koalalorenzo commentedon Mar 15, 2018
I forgot to say: It is NOT a question, this is a bug, because we are expecting helm to handle the rollback. It may cause outages due to the fact that we can't rollback again.
So if we deploy something with
ClusterIP, then we switch toLoadBalancerby mistake and we want to rollback, we will meet this error (if we don't use--force)... then helm is stuck! If we trigger a second rollback, maybe with--forcethis time to "fix" theClusterIPnodePort, all the rollbacks will be "pending", but if we runhelm lsthe deployment will not be there. We can't do anymore ahelm installand we can't do ahelm deletekoalalorenzo commentedon Mar 15, 2018
@bacongobbler Could you label this issue as a Bug or/and give more information?
stuartleeks commentedon Mar 15, 2018
I've just run through the repro steps above and captured a few extra outputs...
(The chart below is just the output of
helm create test)Install with ClusterIP
~/go/src/k8s.io/helm/bin/helm install --name test ./test --set service.type=ClusterIPUpgrade to use LoadBalancer
~/go/src/k8s.io/helm/bin/helm upgrade test ./test --set service.type=LoadBalancerHistory:
Rollback to version 1 (
ClusterIP)~/go/src/k8s.io/helm/bin/helm rollback test 1Note that the history shows
PENDING_ROLLBACKfor the failed rollback. In the tiller logs:At this point
helm lsreturns no entrieshelm installreturnshelm rollback --forcehelm upgradestuartleeks commentedon Mar 15, 2018
After looking into the tiller error, I noticed that this line has
s.recordRelease(targetRelease, false). ThefalsetellsrecordReleaseto try to create the release record but it has already been created byprepareRollbackwith thePENDING_ROLLBACKstatus. I changed this line tos.recordRelease(targetRelease, true)and re-tested, and the tillerfailed to record releaseerror no longer occurred.With this change in place, the history after the failed rollback becomes
However,
helm installandhelm upgradeboth still fail as before.bacongobbler commentedon Mar 15, 2018
Yes, I'll change this to a bug. I was just asleep :)
zaa commentedon Mar 31, 2018
I've tried to reproduce the issue using
kubectl applyand got the same issue. So I think the analysis from @technosophos is right here, you should exposenodePortin the helm chart explicitly and set it to0for the service of typeClusterIP.Second attempt where the port definition has
nodePortset to0:stuartleeks commentedon May 10, 2018
The underlying issue here is that we tried to transition from
ClusterIP->LoadBalancer->ClusterIP, and the second transition failed becausenodePortwas configured byLoadBalancerand is invalid forClusterIP. The comment from @zaa is useful thinking about this going forwards for this particular case.However, in terms of the state of the release in helm I believe that there is an underlying issue with helm: we got to a situation that we could only recover from with helm delete and starting over.
I recently spent some time digging into this with @technosophos and have done some more research since that I'd like to add to the thread for discussion.
In the case of this issue, we arrived at the "no way forward" situation by doing the
LoadBalancer->ClusterIPtransition as a rollback. I figured that it should be possible to do that transition as an upgrade and expected to reach the same "no way forward" situation with helm.... but I didn't!Doing this as a rollback I ended up with:
And at this point neither upgrade nor rollback will allow you to proceed.
However, with upgrade I ended up with:
The key difference here is that we still have a revision marked as deployed.
So for a failed upgrade the previous release is left as
DEPLOYEDwhereas for a failed rollback the previous release is marked asSUPERSEDED.Looking back in history, I first found #1137 that discusses this behaviour and seems to suggest that the current rollback behaviour is expected. There are two PRs referenced from the issue that add in the
SUPERSEDEDbehaviour (tagging @michelleN as the contributor of those PRs :-)). Looking back in the code logs, I then found this change that reversed the behaviour as part of fixing #2437At this point I'm confused as to what the behaviour should be!
What should be the behaviour for rollback/upgrade in terms of whether they leave the previously revision as
DEPLOYEDvsSUPERSEDEDon failure?technosophos commentedon May 11, 2018
/cc @adamreese
adamreese commentedon May 15, 2018
I paired with @technosophos on this and found two issues beings discussed in this thread.
The first one is a bug that was introduced in the refactor on kubernetes v1.10 that no longer validated objects against a schema. Fixed now in #4042. This should capture all the examples listed in the issue.
The second issue is how we handle releases in a failed state. When a failure occurs during a release some resources could be deployed/patched/deleted/created and in a broken state. To calculate a patch to rollback is difficult because we don't know the full state of the cluster anymore. We make assumptions that try to get it close. For helm 3 I am looking at ways we can implement a proper reconcile against cluster resources.
SlickNik commentedon May 16, 2018
@adamreese Thanks for the update and the fix!
Given that we have the fix for this in #4042 and are planning to further address this reconciliation with our Helm 3 design, should we go ahead and close out this issue? Or would you prefer to keep it open to validate the Helm 3 design against?
ritazh commentedon May 18, 2018
Thanks everyone for chiming in and fixing this bug!!! 👏 If it's ok with everyone, let's keep this issue open so we can validate how we handle releases in a failed state against Helm 3.