{% capture overview %} This page shows how to upgrade from Pet Sets (Kubernetes cluster at version 1.3-1.4) to Stateful Sets (version >= 1.5). {% endcapture %}
{% capture prerequisites %}
- If you don't have Pet Sets in your current cluster, or you don't plan to upgrade your cluster/master to >= 1.5 at this moment, you can skip this task now.
{% endcapture %}
{% capture steps %}
Pet Set was introduced as an alpha resource in Kubernetes release 1.3, and was renamed to Stateful Set as a beta resource in 1.5. Here are some notable changes:
- Stateful Set is the new Pet Set: Pet Set is no longer available in any Kubernetes release >= 1.5. It becomes beta Stateful Set.
- Stateful Set fencing: Fencing guards is implemented in >= 1.5 to prevent split brain scenarios for Stateful Sets.
- Flipped debug hook behavior: The behavior of debug hook for Pet Set, i.e. annotation
pod.alpha.kubernetes.io/initialized
, is now flipped for Stateful Sets. The absence of this annotation will pause the Pet Sets, but will NOT pause the Stateful Sets.
First, find all existing Pet Sets in your cluster:
$ kubectl get petsets --all-namespaces
If you don't find any existing Pet Sets, you can safely upgrade your cluster to >= 1.5.
If you find existing Pet Sets and you have all their config files at hand, you can continue to the next step to delete those Pet Sets. Otherwise, you need to save their config so that you can recreate them as Stateful Sets later.
Here's an example command for you to save all existing Pet Sets as one config file.
# Save all existing Pet Sets in all namespaces in a single file. Only needed when you don't have their config files at hand.
$ kubectl get petsets --all-namespaces -o yaml > all-petsets.yaml
If you find existing Pet Sets instead, you need to delete all Pet Sets non-cascadingly. You can do this from kubectl
with --cascade=false
.
Note that if the flag wasn't set, cascading deletion will be performed by default.
# Delete all existing Pet Sets
$ kubectl delete petsets -f <pet-set-file> --cascade=false
# Alternatively, delete them by name and namespace
$ kubectl delete petsets <pet-set-name> -n=<pet-set-namespace> --cascade=false
# Get all Pet Sets again to make sure you deleted them all
$ kubectl get petsets --all-namespaces
At this moment, you've deleted all Pet Sets in your cluster, but not their pods, persistent volumes, or persistent volume claims.
Now, you may upgrade your Kubernetes cluster, or just your master, to >= 1.5.0.
Now, you want to recreate all Pet Sets, but turning them into Stateful Sets. To do this, for every Pet Set config file you have,
change apiVersion
from apps/v1alpha1
to apps/v1beta1
and change kind
from PetSet
to StatefulSet
.
Then you can create Stateful Sets to adopt the pods, persistent volumes, and persistent volume claims previously owned by Pet Sets.
$ kubectl create -f <stateful-set-file>
Now, you can find all Stateful Sets in the newly-upgraded cluster.
$ kubectl get statefulsets --all-namespaces
{% endcapture %}
{% capture whatsnext %} Learn more about debugging a Stateful Set. TODO: Link to the task for debugging a Stateful Set {% endcapture %}
{% include templates/task.md %}