Skip to content

Commit

Permalink
Update StatefulSet Basics for 1.8 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Owens committed Sep 13, 2017
1 parent 2cf12d2 commit 6efa07f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 93 deletions.
103 changes: 12 additions & 91 deletions docs/tutorials/stateful-application/basic-stateful-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,100 +447,12 @@ caused by scaling the StatefulSet down.

## Updating StatefulSets

In Kubernetes 1.7, the StatefulSet controller supports automated updates. The
In Kubernetes 1.7 and later, the StatefulSet controller supports automated updates. The
strategy used is determined by the `spec.updateStrategy` field of the
StatefulSet API Object. This feature can be used to upgrade the container
images, resource requests and/or limits, labels, and annotations of the Pods in a
StatefulSet. There are two valid update strategies, `OnDelete` and
`RollingUpdate`.

### On Delete
The `OnDelete` update strategy implements the legacy (prior to 1.7) behavior,
and it is the default update strategy. When you select this update strategy,
the StatefulSet controller will not automatically update Pods when a
modification is made to the StatefulSet's `.spec.template` field.

Patch the container image for the `web` StatefulSet.

```shell
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"}]'
"web" patched
```

Delete the `web-0` Pod.

```shell
kubectl delete pod web-0
pod "web-0" deleted
```

Watch the `web-0` Pod, and wait for it to transition to Running and Ready.

```shell
kubectl get pod web-0 -w
NAME READY STATUS RESTARTS AGE
web-0 1/1 Running 0 54s
web-0 1/1 Terminating 0 1m
web-0 0/1 Terminating 0 1m
web-0 0/1 Terminating 0 1m
web-0 0/1 Terminating 0 1m
web-0 0/1 Pending 0 0s
web-0 0/1 Pending 0 0s
web-0 0/1 ContainerCreating 0 0s
web-0 1/1 Running 0 3s
```

Get the `web` StatefulSet's Pods to view their container images.

```shell{% raw %}
kubectl get pod -l app=nginx -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
web-0 gcr.io/google_containers/nginx-slim:0.7
web-1 gcr.io/google_containers/nginx-slim:0.8
web-2 gcr.io/google_containers/nginx-slim:0.8
{% endraw %}```

`web-0` has had its image updated, but `web-1` and `web-2` still have the original
image. Complete the update by deleting the remaining Pods.

```shell
kubectl delete pod web-1 web-2
pod "web-1" deleted
pod "web-2" deleted
```

Watch the StatefulSet's Pods, and wait for all of them to transition to Running and Ready.

```
kubectl get pods -w -l app=nginx
NAME READY STATUS RESTARTS AGE
web-0 1/1 Running 0 8m
web-1 1/1 Running 0 4h
web-2 1/1 Running 0 23m
NAME READY STATUS RESTARTS AGE
web-1 1/1 Terminating 0 4h
web-1 1/1 Terminating 0 4h
web-1 0/1 Pending 0 0s
web-1 0/1 Pending 0 0s
web-1 0/1 ContainerCreating 0 0s
web-2 1/1 Terminating 0 23m
web-2 1/1 Terminating 0 23m
web-1 1/1 Running 0 4s
web-2 0/1 Pending 0 0s
web-2 0/1 Pending 0 0s
web-2 0/1 ContainerCreating 0 0s
web-2 1/1 Running 0 36s
```

Get the Pods to view their container images.

```shell{% raw %}
kubectl get pod -l app=nginx -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
web-0 gcr.io/google_containers/nginx-slim:0.7
web-1 gcr.io/google_containers/nginx-slim:0.7
web-2 gcr.io/google_containers/nginx-slim:0.7
{% endraw %}```

All the Pods in the StatefulSet are now running a new container image.
StatefulSet. There are two valid update strategies, `RollingUpdate` and
`OnDelete`.

### Rolling Update

Expand Down Expand Up @@ -797,6 +709,15 @@ gcr.io/google_containers/nginx-slim:0.7
By moving the `partition` to `0`, you allowed the StatefulSet controller to
continue the update process.
### On Delete
The `OnDelete` update strategy implements the legacy (1.6 and prior) behavior,
When you select this update strategy, the StatefulSet controller will not
automatically update Pods when a modification is made to the StatefulSet's
`.spec.template` field. This strategy can be selected by setting the
`.spec.template.updateStrategy.type` to `OnDelete`.


## Deleting StatefulSets

StatefulSet supports both Non-Cascading and Cascading deletion. In a
Expand Down
5 changes: 4 additions & 1 deletion docs/tutorials/stateful-application/web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ spec:
selector:
app: nginx
---
apiVersion: apps/v1beta1
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
Expand Down
5 changes: 4 additions & 1 deletion docs/tutorials/stateful-application/webp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ spec:
selector:
app: nginx
---
apiVersion: apps/v1beta1
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
podManagementPolicy: "Parallel"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
Expand Down

0 comments on commit 6efa07f

Please sign in to comment.