Skip to content

Commit 90d95e7

Browse files
kow3nssteveperry-53
authored andcommitted
Update StatefulSet Basics for 1.8 release (#5398)
1 parent 3810cb2 commit 90d95e7

File tree

3 files changed

+20
-93
lines changed

3 files changed

+20
-93
lines changed

docs/tutorials/stateful-application/basic-stateful-set.md

+12-91
Original file line numberDiff line numberDiff line change
@@ -447,100 +447,12 @@ caused by scaling the StatefulSet down.
447447

448448
## Updating StatefulSets
449449

450-
In Kubernetes 1.7, the StatefulSet controller supports automated updates. The
450+
In Kubernetes 1.7 and later, the StatefulSet controller supports automated updates. The
451451
strategy used is determined by the `spec.updateStrategy` field of the
452452
StatefulSet API Object. This feature can be used to upgrade the container
453453
images, resource requests and/or limits, labels, and annotations of the Pods in a
454-
StatefulSet. There are two valid update strategies, `OnDelete` and
455-
`RollingUpdate`.
456-
457-
### On Delete
458-
The `OnDelete` update strategy implements the legacy (prior to 1.7) behavior,
459-
and it is the default update strategy. When you select this update strategy,
460-
the StatefulSet controller will not automatically update Pods when a
461-
modification is made to the StatefulSet's `.spec.template` field.
462-
463-
Patch the container image for the `web` StatefulSet.
464-
465-
```shell
466-
kubectl patch statefulset web --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"gcr.io/google_containers/nginx-slim:0.7"}]'
467-
"web" patched
468-
```
469-
470-
Delete the `web-0` Pod.
471-
472-
```shell
473-
kubectl delete pod web-0
474-
pod "web-0" deleted
475-
```
476-
477-
Watch the `web-0` Pod, and wait for it to transition to Running and Ready.
478-
479-
```shell
480-
kubectl get pod web-0 -w
481-
NAME READY STATUS RESTARTS AGE
482-
web-0 1/1 Running 0 54s
483-
web-0 1/1 Terminating 0 1m
484-
web-0 0/1 Terminating 0 1m
485-
web-0 0/1 Terminating 0 1m
486-
web-0 0/1 Terminating 0 1m
487-
web-0 0/1 Pending 0 0s
488-
web-0 0/1 Pending 0 0s
489-
web-0 0/1 ContainerCreating 0 0s
490-
web-0 1/1 Running 0 3s
491-
```
492-
493-
Get the `web` StatefulSet's Pods to view their container images.
494-
495-
```shell{% raw %}
496-
kubectl get pod -l app=nginx -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
497-
web-0 gcr.io/google_containers/nginx-slim:0.7
498-
web-1 gcr.io/google_containers/nginx-slim:0.8
499-
web-2 gcr.io/google_containers/nginx-slim:0.8
500-
{% endraw %}```
501-
502-
`web-0` has had its image updated, but `web-1` and `web-2` still have the original
503-
image. Complete the update by deleting the remaining Pods.
504-
505-
```shell
506-
kubectl delete pod web-1 web-2
507-
pod "web-1" deleted
508-
pod "web-2" deleted
509-
```
510-
511-
Watch the StatefulSet's Pods, and wait for all of them to transition to Running and Ready.
512-
513-
```
514-
kubectl get pods -w -l app=nginx
515-
NAME READY STATUS RESTARTS AGE
516-
web-0 1/1 Running 0 8m
517-
web-1 1/1 Running 0 4h
518-
web-2 1/1 Running 0 23m
519-
NAME READY STATUS RESTARTS AGE
520-
web-1 1/1 Terminating 0 4h
521-
web-1 1/1 Terminating 0 4h
522-
web-1 0/1 Pending 0 0s
523-
web-1 0/1 Pending 0 0s
524-
web-1 0/1 ContainerCreating 0 0s
525-
web-2 1/1 Terminating 0 23m
526-
web-2 1/1 Terminating 0 23m
527-
web-1 1/1 Running 0 4s
528-
web-2 0/1 Pending 0 0s
529-
web-2 0/1 Pending 0 0s
530-
web-2 0/1 ContainerCreating 0 0s
531-
web-2 1/1 Running 0 36s
532-
```
533-
534-
Get the Pods to view their container images.
535-
536-
```shell{% raw %}
537-
kubectl get pod -l app=nginx -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
538-
web-0 gcr.io/google_containers/nginx-slim:0.7
539-
web-1 gcr.io/google_containers/nginx-slim:0.7
540-
web-2 gcr.io/google_containers/nginx-slim:0.7
541-
{% endraw %}```
542-
543-
All the Pods in the StatefulSet are now running a new container image.
454+
StatefulSet. There are two valid update strategies, `RollingUpdate` and
455+
`OnDelete`.
544456

545457
### Rolling Update
546458

@@ -797,6 +709,15 @@ gcr.io/google_containers/nginx-slim:0.7
797709
By moving the `partition` to `0`, you allowed the StatefulSet controller to
798710
continue the update process.
799711
712+
### On Delete
713+
714+
The `OnDelete` update strategy implements the legacy (1.6 and prior) behavior,
715+
When you select this update strategy, the StatefulSet controller will not
716+
automatically update Pods when a modification is made to the StatefulSet's
717+
`.spec.template` field. This strategy can be selected by setting the
718+
`.spec.template.updateStrategy.type` to `OnDelete`.
719+
720+
800721
## Deleting StatefulSets
801722

802723
StatefulSet supports both Non-Cascading and Cascading deletion. In a

docs/tutorials/stateful-application/web.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ spec:
1313
selector:
1414
app: nginx
1515
---
16-
apiVersion: apps/v1beta1
16+
apiVersion: apps/v1beta2
1717
kind: StatefulSet
1818
metadata:
1919
name: web
2020
spec:
2121
serviceName: "nginx"
2222
replicas: 2
23+
selector:
24+
matchLabels:
25+
app: nginx
2326
template:
2427
metadata:
2528
labels:

docs/tutorials/stateful-application/webp.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ spec:
1313
selector:
1414
app: nginx
1515
---
16-
apiVersion: apps/v1beta1
16+
apiVersion: apps/v1beta2
1717
kind: StatefulSet
1818
metadata:
1919
name: web
2020
spec:
2121
serviceName: "nginx"
2222
podManagementPolicy: "Parallel"
2323
replicas: 2
24+
selector:
25+
matchLabels:
26+
app: nginx
2427
template:
2528
metadata:
2629
labels:

0 commit comments

Comments
 (0)