Intro
Longhorn can be upgraded with modified Storage Class.
Related Issue
https://github.com/longhorn/longhorn/issues/1527
Test steps:
Kubectl apply -f
- Install Longhorn v1.0.2
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.0.2/deploy/longhorn.yaml - Create a statefulset using
longhornstorageclass for PVCs. Set the scale to 1. - Observe that there is a workload pod (
pod-1) is using 1 volume (vol-1) with 3 replicas. - In Longhorn repo, on
masterbranch. ModifynumberOfReplicas: "1"inhttps://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml. Upgrade Longhorn to master by runningkubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml - Verify that
longhornstorage class now has the fieldnumberOfReplicas: 1. - Scale up the deployment to 2. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.
- Scale up the deployment to 0 then back to 2. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.
Helm
-
Follow this instruction to install Longhorn v1.0.2 using Helm https://longhorn.io/docs/1.0.2/deploy/install/install-with-helm/#installing-longhorn
-
Create a statefulSet using
longhornstorage class for PVCs. Set the scale to 1. -
Observe that there is a workload pod (
pod-1) is using 1 volume (vol-1) with 3 replicas. -
Clone the longhorn chart in local system and checkout to Longhorn repo, upgrade Longhorn to the master version by running:
helm upgrade longhorn chart/ -n longhorn-system --set persistence.defaultClassReplicaCount=1,image.longhorn.manager.tag=master -
Verify that no error occurs.
-
Verify that
longhornstorage class now has the fieldnumberOfReplicas: 1. -
Scale up the deployment to 2. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.
-
Scale up the deployment to 0 then back to 2. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.
-
Upgrade Longhorn again by running:
helm upgrade longhorn chart/ -n longhorn-system --set persistence.defaultClassReplicaCount=2,image.longhorn.manager.tag=master -
Verify that no error occurs.
-
Verify that
longhornstorage class now has the fieldnumberOfReplicas: 2. -
Scale up the deployment to 3. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.pod-3is using volumevol-3with 2 replicas.
-
See the current Longhorn release’s
revision:helm list -n longhorn-system -
Rollback to the previous version by:
helm rollback longhorn <REVISION - 1> -n longhorn-system -
Verify that no error occurs.
-
Verify that
longhornstorage class now has the fieldnumberOfReplicas: 1. -
Scale up the deployment to 4. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.pod-3is using volumevol-3with 2 replicas.pod-4is using volumevol-4with 1 replicas.
-
Rollback to the very first version by:
helm rollback longhorn 1 -n longhorn-system -
See the error:
Error: no StorageClass with the name "longhorn" foundThis is because the Longhorn master version already replaced the initial
longhornstorage class by a different version. Users have to manually deletelonghornstorage class before they can rollback. In the future (e.g. when upgrade/rollback between v.1.1 +) this issue will not happen because the versions after v1.1+ we don’t use Helm template forlonghornstorage class
Rancher UI
- Install Longhorn v1.0.2 using the rancher app catalog.
- Create a statefulSet using
longhornstorage class for PVCs. Set the scale to 1. - Observe that there is a workload pod (
pod-1) is using 1 volume (vol-1) with 3 replicas. - From Rancher UI, upgrade the chart to v1.1.0. In the upgrading UI, change parameter
Default Storage Class Replica Count: 1before clicking Save - Verify that no error occurs.
- Verify that
longhornstorage class now has the fieldnumberOfReplicas: 1. - Scale up the deployment to 2. Verify that:
pod-1is using volumevol-1with 3 replicas.pod-2is using volumevol-2with 1 replica.