To decide how to handle updates, StatefulSet
objects use an update strategy
defined in the .spec.updateStrategy
section of its manifest. There are two
strategies, OnDelete
and RollingUpdate
:
OnDelete
does not delete and recreatePod
objects when the object's configuration changes. Instead, you must manually delete the oldPod
objects for the controller to create updatedPod
objects.RollingUpdate
deletes and recreatesPod
objects when the object's configuration changes. NewPod
objects must be inRunning
andReady
states before their predecessors are deleted. With this strategy, changing thePod
specification prompts a rollout. This is the default update strategy forStatefulSet
objects.
There are multiple ways of updating StatefulSet
objects. The common,
declarative method is kubectl apply
. To update a StatefulSet
directly from
your shell or in a preferred editor, use kubectl edit
. You can roll out
updates to the Pod
's specification for a StatefulSet
resource, such as its
image, resource usage, resource requests, or configuration.
StatefulSet
objects use an ordinal index for the identity and ordering of
their Pod
objects. By default, the pods of a StatefulSet
are deployed in
sequential order and are terminated in the reverse ordinal order. For example, a
StatefulSet
named web
has its Pod
objects named web-0
, web-1
, and
web-2
. When the StatefulSet
specification is changed, its Pod
objects are
gracefully stopped and recreated in an ordered way. In this example, the pod
named web-2
is terminated first, then web-1
, and so on.
Alternatively, you can specify the podManagementPolicy: Parallel
field to have
a StatefulSet
resource launch or terminate all of its Pod
objects in
parallel, rather than waiting for Pod
objects to become running and ready or
to be terminated prior to launching or terminating another pod.
Before you begin
To run commands against a user cluster, ensure you have the following resources:
Locate the user cluster name, or ask your Platform Administrator what the cluster name is.
Sign in and generate the kubeconfig file for the user cluster if you don't have one.
Use the kubeconfig path of the user cluster to replace
USER_CLUSTER_KUBECONFIG
in these instructions.
To get the required permissions to update stateful workloads, ask your Organization IAM Admin to grant you the Namespace Admin role.
Update a StatefulSet
resource
To update the StatefulSet
, apply a new or updated manifest file. This is
useful for making various changes to your StatefulSet
when scaling or for
specifying a new version of your application.
To update a StatefulSet
object, run:
kubectl --kubeconfig USER_CLUSTER_KUBECONFIG \
apply -f STATEFULSET_FILE
Replace the following:
USER_CLUSTER_KUBECONFIG
: the kubeconfig file for the user cluster running the stateful workloads.STATEFULSET_FILE
: the name of the updatedStatefulSet
manifest file.
The kubectl apply
command applies a manifest file to a resource. If the
specified resource does not exist, it is created by the command.
Inspect a StatefulSet
resource update rollout
You can view detailed information regarding the update rollout status and
history of a StatefulSet
object. You can also undo a rollout of a
StatefulSet
object.
Inspect the rollout
To inspect the rollout of the StatefulSet
resource, run:
kubectl --kubeconfig USER_CLUSTER_KUBECONFIG \
rollout status statefulset STATEFULSET_NAME
USER_CLUSTER_KUBECONFIG
: the kubeconfig file for the user cluster running the stateful workloads.STATEFULSET_NAME
: the name of the updatedStatefulSet
object.
Get the rollout history
To see the StatefulSet
resource's rollout history, run:
kubectl --kubeconfig USER_CLUSTER_KUBECONFIG \
rollout history statefulset STATEFULSET_NAME
USER_CLUSTER_KUBECONFIG
: the kubeconfig file for the user cluster running the stateful workloads.STATEFULSET_NAME
: the name of the updatedStatefulSet
object.
Undo a rollout
To undo a rollout, run:
kubectl --kubeconfig USER_CLUSTER_KUBECONFIG \
rollout undo statefulset STATEFULSET_NAME
Replace the following:
USER_CLUSTER_KUBECONFIG
: the kubeconfig file for the user cluster running the stateful workloads.STATEFULSET_NAME
: the name of theStatefulSet
object.