This document shows how to upgrade a Pravega cluster managed by the operator to a desired version while preserving the cluster's state and data whenever possible.
The activity diagram below shows the overall upgrade process started by an end-user and performed by the operator.
Your Bookkeeper cluster should be in a healthy state. You can check your cluster health by listing it and checking that all members are ready.
$ kubectl get BookkeeperCluster
NAME VERSION DESIRED MEMBERS READY MEMBERS AGE
pravega-bk 0.6.1 7 7 11m
BASE VERSION | TARGET VERSION |
---|---|
0.1.0 | 0.1.0 |
0.2.0 | 0.2.0 |
0.3.0 | 0.3.0, 0.3.1, 0.3.2 |
0.3.1 | 0.3.1, 0.3.2 |
0.3.2 | 0.3.2 |
0.4.0 | 0.4.0 |
0.5.0 | 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.7.0 |
0.5.1 | 0.5.1, 0.6.0, 0.6.1, 0.7.0 |
0.6.0 | 0.6.0, 0.6.1, 0.7.0 |
0.6.1 | 0.6.1, 0.7.0 |
0.7.0 | 0.7.0 |
To initiate an upgrade process, a user has to update the spec.version
field on the BookkeeperCluster
custom resource. This can be done in three different ways using the kubectl
command.
kubectl edit BookkeeperCluster <name>
, modify theversion
value in the YAML resource, save, and exit.- If you have the custom resource defined in a local YAML file, e.g.
bookkeeper.yaml
, you can modify theversion
value, and reapply the resource withkubectl apply -f bookkeeper.yaml
. kubectl patch BookkeeperCluster <name> --type='json' -p='[{"op": "replace", "path": "/spec/version", "value": "X.Y.Z"}]'
. After theversion
field is updated, the operator will detect the version change and it will trigger the upgrade process.
Once an upgrade request has been received, the operator will apply the rolling upgrade to the Bookkeeper STS.
The upgrade workflow is as follows:
- The operator will change the
Upgrade
condition toTrue
to indicate that the cluster resource has an upgrade in progress.- If any of the component pods has errors, the upgrade process will stop (
Upgrade
condition toFalse
) and operator will set theError
condition toTrue
and indicate the reason.
- If any of the component pods has errors, the upgrade process will stop (
- When all pods are upgraded, the
Upgrade
condition will be set toFalse
andstatus.currentVersion
will be updated to the desired version.
BookKeeper cluster is deployed as a StatefulSet due to its requirements on:
- Persistent storage: each bookie has three persistent volume for ledgers, journals, and indices. If a pod is migrated or recreated (e.g. when it's upgraded), the data in those volumes will remain untouched.
- Stable network names: the
StatefulSet
provides pods with a predictable name and a Headless service creates DNS records for pods to be reachable by clients. If a pod is recreated or migrated to a different node, clients will continue to be able to reach the pod despite changing its IP address.
Statefulset upgrade strategy is configured in the updateStrategy
field. It supports two type of strategies.
RollingUpdate
. The statefulset will automatically apply a rolling upgrade to the pods.OnDelete
. The statefulset will not automatically upgrade pods. Pods will be updated when they are recreated after being deleted.
In both cases, the upgrade is initiated when the Pod template is updated.
For BookKeeper, the operator uses an OnDelete
strategy. With RollingUpdate
strategy, you can only check the upgrade status once all pods get upgraded. On the other hand, with OnDelete
you can keep updating pod one by one and keep checking the application status to make sure the upgrade working fine. This allows the operator to have control over the upgrade process and perform verifications and actions before and after a BookKeeper pod is upgraded. For example, checking that there are no under-replicated ledgers before upgrading the next pod. Also, the operator might be need to apply migrations when upgrading to a certain version.
BookKeeper upgrade process is as follows:
- Statefulset Pod template is updated to the new image and tag according to the Pravega version.
- Pick one outdated pod
- Apply pre-upgrade actions and verifications
- Delete the pod. The pod is recreated with an updated spec and version
- Wait for the pod to become ready. If it fails to start or times out, the upgrade is cancelled. Check Recovering from a failed upgrade
- Apply post-upgrade actions and verifications
- If all pods are updated, BookKeeper upgrade is completed. Otherwise, go to 2.
You can monitor the upgrade process by listing the Bookkeeper clusters. If a desired version is shown, it means that the operator is working on updating the version.
$ kubectl get BookkeeperCluster
NAME VERSION DESIRED VERSION DESIRED MEMBERS READY MEMBERS AGE
example 0.4.0 0.5.0 4 3 1h
When the upgrade process has finished, the version will be updated.
$ kubectl get BookkeeperCluster
NAME VERSION DESIRED MEMBERS READY MEMBERS AGE
example 0.5.0 4 4 1h
The command kubectl describe
can be used to track progress of the upgrade.
$ kubectl describe BookkeeperCluster example
...
Status:
Conditions:
Status: True
Type: Upgrading
Reason: Updating BookKeeper
Message: 1
Last Transition Time: 2019-04-01T19:42:37+02:00
Last Update Time: 2019-04-01T19:42:37+02:00
Status: False
Type: PodsReady
Last Transition Time: 2019-04-01T19:43:08+02:00
Last Update Time: 2019-04-01T19:43:08+02:00
Status: False
Type: Error
...
The Reason
field in Upgrading Condition shows the component currently being upgraded and Message
field reflects number of successfully upgraded replicas in this component.
If upgrade has failed, please check the Status
section to understand the reason for failure.
$ kubectl describe BookkeeperCluster example
...
Status:
Conditions:
Status: False
Type: Upgrading
Last Transition Time: 2019-04-01T19:42:37+02:00
Last Update Time: 2019-04-01T19:42:37+02:00
Status: False
Type: PodsReady
Last Transition Time: 2019-04-01T19:43:08+02:00
Last Update Time: 2019-04-01T19:43:08+02:00
Message: failed to sync bookkeeper version. pod example-bookie-0 is restarting
Reason: UpgradeFailed
Status: True
Type: Error
Current Replicas: 8
Current Version: 0.4.0
Members:
Ready:
example-bookie-1
example-bookie-2
example-bookie-2
example-bookie-2
Unready:
example-bookie-0
Ready Replicas: 3
Replicas: 4
You can also find useful information at the operator logs.
...
INFO[5884] syncing cluster version from 0.4.0 to 0.5.0-1
INFO[5885] Reconciling BookkeeperCluster default/example
INFO[5886] updating statefulset (example-bookie) template image to 'adrianmo/bookkeeper:0.5.0-1'
INFO[5896] Reconciling BookkeeperCluster default/example
INFO[5897] statefulset (example-bookie) status: 0 updated, 3 ready, 3 target
INFO[5897] upgrading pod: example-bookie-0
INFO[5899] Reconciling BookkeeperCluster default/example
INFO[5900] statefulset (example-bookie) status: 1 updated, 2 ready, 3 target
INFO[5929] Reconciling BookkeeperCluster default/example
INFO[5930] statefulset (example-bookie) status: 1 updated, 2 ready, 3 target
INFO[5930] error syncing cluster version, upgrade failed. failed to sync bookkeeper version. pod example-bookie-0 is restarting
...
See Rollback