Force a k8s/helm deployment to recreate pods

In some cases when upgrading a pod that has an attached PVC that does not allow ReadWriteMany, kubernetes might start creating the new pod but since it can't attach it to the PVC as the pod we want to update is already attached to it, the new pod might stay in ContainerCreating state.

This could happen due to be using a RollingUpgrade deployemnt strategy. In cases where a small down-time is not a problem, we can just solve this problem by using the Recreate strategy.

To do so in Helm the updateStrategy should be changed from:

updateStrategy:
  type: RollingUpdate
  rollingUpdate: {}

to:

updateStrategy:
  type: Recreate
  rollingUpdate: null

And in a kubernetes deployment manifest, instead of changing the updateStrategy key, we should change the strategy key as can be seen in the following example:

strategy:
  type: RollingUpdate
  rollingUpdate: {}

to:

strategy:
  type: Recreate
  rollingUpdate: null

Note that if the rollingUpdate value is not updated to null, the following error will be raised:

Error: UPGRADE FAILED: cannot patch "helm-deployment-example" with kind Deployment: Deployment.apps "helm-deployment-example" is invalid: spec.strategy.rollingUpdate: Forbidden: may not be specified when strategy `type` is 'Recreate'

Also note that until helm version 2, the flag --recreate-pods could also be used to achieve the same result, but starting from version 3, it has been deprecated.