2016-11-28 22:22:55 +00:00
|
|
|
---
|
2018-02-18 20:13:37 +00:00
|
|
|
reviewers:
|
2016-11-28 22:22:55 +00:00
|
|
|
- enisoc
|
|
|
|
- erictune
|
|
|
|
- foxish
|
|
|
|
- janetkuo
|
|
|
|
- kow3ns
|
|
|
|
- smarterclayton
|
2016-12-15 20:16:54 +00:00
|
|
|
title: StatefulSet Basics
|
2020-05-30 19:10:23 +00:00
|
|
|
content_type: tutorial
|
2018-05-15 22:29:27 +00:00
|
|
|
weight: 10
|
2016-11-28 22:22:55 +00:00
|
|
|
---
|
|
|
|
|
2020-05-30 19:10:23 +00:00
|
|
|
<!-- overview -->
|
2017-09-21 09:22:42 +00:00
|
|
|
This tutorial provides an introduction to managing applications with
|
2020-05-25 00:15:30 +00:00
|
|
|
{{< glossary_tooltip text="StatefulSets" term_id="statefulset" >}}.
|
|
|
|
It demonstrates how to create, delete, scale, and update the Pods of StatefulSets.
|
|
|
|
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-30 19:10:23 +00:00
|
|
|
## {{% heading "prerequisites" %}}
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Before you begin this tutorial, you should familiarize yourself with the
|
2020-05-25 00:15:30 +00:00
|
|
|
following Kubernetes concepts:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2019-12-16 14:17:37 +00:00
|
|
|
* [Pods](/docs/concepts/workloads/pods/)
|
2017-04-19 17:56:47 +00:00
|
|
|
* [Cluster DNS](/docs/concepts/services-networking/dns-pod-service/)
|
2017-04-20 12:08:43 +00:00
|
|
|
* [Headless Services](/docs/concepts/services-networking/service/#headless-services)
|
2017-09-21 03:46:28 +00:00
|
|
|
* [PersistentVolumes](/docs/concepts/storage/persistent-volumes/)
|
2021-08-10 03:15:28 +00:00
|
|
|
* [PersistentVolume Provisioning](https://github.com/kubernetes/examples/tree/master/staging/persistent-volume-provisioning/)
|
2020-05-25 00:15:30 +00:00
|
|
|
* The [kubectl](/docs/reference/kubectl/kubectl/) command line tool
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:18:47 +00:00
|
|
|
{{% include "task-tutorial-prereqs.md" %}}
|
|
|
|
You should configure `kubectl` to use a context that uses the `default`
|
|
|
|
namespace.
|
|
|
|
If you are using an existing cluster, make sure that it's OK to use that
|
|
|
|
cluster's default namespace to practice. Ideally, practice in a cluster
|
|
|
|
that doesn't run any real workloads.
|
|
|
|
|
|
|
|
It's also useful to read the concept page about [StatefulSets](/docs/concepts/workloads/controllers/statefulset/).
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
{{< note >}}
|
2020-05-24 23:32:37 +00:00
|
|
|
This tutorial assumes that your cluster is configured to dynamically provision
|
2023-09-20 17:18:47 +00:00
|
|
|
PersistentVolumes. You'll also need to have a [default StorageClass](/docs/concepts/storage/storage-classes/#default-storageclass).
|
|
|
|
If your cluster is not configured to provision storage dynamically, you
|
2020-05-24 23:32:37 +00:00
|
|
|
will have to manually provision two 1 GiB volumes prior to starting this
|
2023-09-20 17:18:47 +00:00
|
|
|
tutorial and
|
|
|
|
set up your cluster so that those PersistentVolumes map to the
|
|
|
|
PersistentVolumeClaim templates that the StatefulSet defines.
|
2020-05-25 00:15:30 +00:00
|
|
|
{{< /note >}}
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-30 19:10:23 +00:00
|
|
|
## {{% heading "objectives" %}}
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
StatefulSets are intended to be used with stateful applications and distributed
|
|
|
|
systems. However, the administration of stateful applications and
|
|
|
|
distributed systems on Kubernetes is a broad, complex topic. In order to
|
|
|
|
demonstrate the basic features of a StatefulSet, and not to conflate the former
|
2017-06-27 16:46:39 +00:00
|
|
|
topic with the latter, you will deploy a simple web application using a StatefulSet.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
After this tutorial, you will be familiar with the following.
|
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
* How to create a StatefulSet
|
|
|
|
* How a StatefulSet manages its Pods
|
|
|
|
* How to delete a StatefulSet
|
|
|
|
* How to scale a StatefulSet
|
2017-06-27 16:46:39 +00:00
|
|
|
* How to update a StatefulSet's Pods
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-30 19:10:23 +00:00
|
|
|
<!-- lessoncontent -->
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
## Creating a StatefulSet
|
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Begin by creating a StatefulSet (and the Service that it relies upon) using
|
|
|
|
the example below. It is similar to the example presented in the
|
2020-05-24 23:32:37 +00:00
|
|
|
[StatefulSets](/docs/concepts/workloads/controllers/statefulset/) concept.
|
2020-05-25 00:15:30 +00:00
|
|
|
It creates a [headless Service](/docs/concepts/services-networking/service/#headless-services),
|
2020-05-24 23:32:37 +00:00
|
|
|
`nginx`, to publish the IP addresses of Pods in the StatefulSet, `web`.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-24 10:38:23 +00:00
|
|
|
{{% code_sample file="application/web/web.yaml" %}}
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-11-17 19:00:24 +00:00
|
|
|
You will need to use at least two terminal windows. In the first terminal, use
|
2024-07-04 14:09:12 +00:00
|
|
|
[`kubectl get`](/docs/reference/generated/kubectl/kubectl-commands/#get) to {{< glossary_tooltip text="watch" term_id="watch" >}} the creation
|
2016-11-29 18:01:38 +00:00
|
|
|
of the StatefulSet's Pods.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# use this terminal to run commands that specify --watch
|
|
|
|
# end this watch when you are asked to start a new watch
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
In the second terminal, use
|
Official 1.14 Release Docs (#13174)
* Official documentation on Poseidon/Firmament, a new multi-scheduler support for K8S. (#11752)
* Added documentation about Poseidon-Firmament scheduler
* Fixed some style issues.
* Udpated the document as per the review comments.
* Fixed some typos and updated the document
* Updated the document as per the review comments.
* Document timeout attribute for kms-plugin. (#12158)
See 72540.
* Official documentation on Poseidon/Firmament, a new multi-scheduler (#12343)
* Removed the old version of the Poseidon documentation. Incorrect location.
* Official documentation on Poseidon/Firmament, a new multi-scheduler support for K8S (#12069)
* Official documentation on Poseidon/Firmament, a new multi-scheduler support for K8S. (#11752)
* Added documentation about Poseidon-Firmament scheduler
* Fixed some style issues.
* Udpated the document as per the review comments.
* Fixed some typos and updated the document
* Updated the document as per the review comments.
* Updated the document as per review comments. Added config details.
* Updated the document as per the latest review comments. Fixed nits
* Made changes as per latest suggestions.
* Some more changes added.
* Updated as per suggestions.
* Changed the release process section.
* SIG Docs edits
Small edits to match style guidelines.
* add plus to feature state
* capitalization
* revert feature state shortcode
since this is a Kubernetes extension, not a direct feature, it shouldn't use the regular feature state tagging.
(cherry picked from commit 7730c1540b637be74b9b21d4128a145994eb19cc)
* Remove initializers from doc. It will be removed in 1.14 (#12331)
* kubeadm: Document CRI auto detection functionality (#12462)
Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
* Minor doc change for GAing Pod DNS Config (#12514)
* Graduate ExpandInUsePersistentVolumes feature to beta (#10574)
* Rename 2018-11-07-grpc-load-balancing-with-linkerd.md.md file (#12594)
* Add dynamic percentage of node scoring to user docs (#12235)
* Add dynamic percentage of node scoring to user docs
* addressed review comments
* delete special symbol (#12445)
* Update documentation for VolumeSubpathEnvExpansion (#11843)
* Update documentation for VolumeSubpathEnvExpansion
* Address comments - improve descriptions
* Graduate Pod Priority and Preemption to GA (#12428)
* Added Instana links to the documentation (#12977)
* Added link to the Instana Kubernetes integration
* Added Instana link for services section
Added Instana and a link to the Kubernetes integration to the analytics services section and broadened the scope to APM, monitoring and analytics.
* Oxford comma /flex
* More Oxford commas, because they matter
* Update kubectl plugins to stable (#12847)
* documentation for CSI topology beta (#12889)
* Document changes to default RBAC discovery ClusterRole(Binding)s (#12888)
* Document changes to default RBAC discovery ClusterRole(Binding)s
Documentation for https://github.com/kubernetes/enhancements/issues/789 and https://github.com/kubernetes/kubernetes/pull/73807
* documentation review feedback
* CSI raw block to beta (#12931)
* Change incorrect string raw to block (#12926)
Fixes #12925
* Update documentation on node OS/arch labels (#12976)
These labels have been promoted to GA:
https://github.com/kubernetes/enhancements/issues/793
* local pv GA doc updates (#12915)
* Publish CRD OpenAPI Documentation (#12910)
* add documentation for CustomResourcePublishOpenAPI
* address comments
fix links, ordered lists, style and typo
* kubeadm: add document for upgrading from 1.13 to 1.14 (single CP and HA) (#13189)
* kubeadm: add document for upgrading from 1.13 to 1.14
- remove doc for upgrading 1.10 -> 1.11
* kubeadm: apply amends to upgrade-1.14 doc
* kubeadm: apply amends to upgrade-1.14 doc (part2)
* kubeadm: apply amends to upgrade-1.14 doc (part3)
* kubeadm: add note about "upgrade node experimental-control-plane"
+ add comment about `upgrade plan`
* kubeadm: add missing "You should see output similar to this"
* fix bullet indentation (#13214)
* mark PodReadinessGate GA (#12800)
* Update RuntimeClass documentation for beta (#13043)
* Update RuntimeClass documentation for beta
* Update feature gate & add upgrade section
* formatting fixes
* Highlight upgrade action required
* Address feedback
* CSI ephemeral volume alpha documentation (#10934)
* update kubectl documentation (#12867)
* update kubectl documentation
* add document for Secret/ConfigMap generators
* replace `kubectl create -f` by `kubectl apply -f`
* Add page for kustomization support in kubectl
* fix spelling errors and address comments
* Documentation for Windows GMSA feature (#12936)
* Documentation for Windows GMSA feature
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Enhancements to GMSA docs
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Fix links
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Fix GMSA link
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Add GMSA feature flag in feature flag list
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Relocate GMSA to container configuration
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Add example for container spec
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Remove changes in Windows index
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Update configure-gmsa.md
* Update configure-gmsa.md
* Update configure-gmsa.md
* Update configure-gmsa.md
* Rearrange the steps into two sections and other edits
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Fix links
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Add reference to script to generate GMSA YAMLs
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Some more clarifications for GMSA
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* HugePages graduated to GA (#13004)
* HugePages graduated to GA
* fixing nit for build
* Docs for node PID limiting (https://github.com/kubernetes/kubernetes/pull/73651) (#12932)
* kubeadm: update the reference documentation for 1.14 (#12911)
* kubeadm: update list of generated files for 1.14
NOTE: PLACEHOLDERS! these files are generated by SIG Docs each
release, but we need them to pass the k/website PR CI.
- add join_phase* (new sub phases of join)
- add init_phase_upload-certs.md (new upload certs phase for init)
- remove alpha-preflight (now both init and join have this)
* kubeadm: update reference docs includes for 1.14
- remove includes from alpha.md
- add upload-certs to init-phase.md
- add join-phase.md and it's phases
* kubeadm: update the editorial content of join and init
- cleanup master->control-plane node
- add some notes about phases and join
- remove table about pre-pulling images
- remove outdated info about self-hosting
* kubeadm: update target release for v1alpha3 removal
1.14 -> 1.15
* kubeadm: copy edits for 1.14 reference docs (part1)
* kubeadm: use "shell" for code blocks
* kubeadm: update the 1.14 HA guide (#13191)
* kubeadm: update the 1.14 HA guide
* kubeadm: try to fix note/caution indent in HA page
* kubeadm: fix missing sudo and minor amends in HA doc
* kubeadm: apply latest amends to the HA doc for 1.14
* fixed a few missed merge conflicts
* Admission Webhook new features doc (#12938)
- kubernetes/kubernetes#74998
- kubernetes/kubernetes#74477
- kubernetes/kubernetes#74562
* Clarifications and fixes in GMSA doc (#13226)
* Clarifications and fixes in GMSA doc
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Update configure-gmsa.md
* Reformat to align headings and pre-reqs better
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Reformat to align headings and pre-reqs better
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Reformat to fix bullets
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Reword application of sample gmsa
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Update configure-gmsa.md
* Address feedback to use active voice
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Address feedback to use active voice
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* RunAsGroup documentation for Progressing this to Beta (#12297)
* start serverside-apply documentation (#13077)
* start serverside-apply documentation
* add more concept info on server side apply
* Update api concepts
* Update api-concepts.md
* fix style issues
* Document CSI update (#12928)
* Document CSI update
* Finish CSI documentation
Also fix mistake with ExpandInUsePersistentVolumes documented as beta
* Overall docs for CSI Migration feature (#12935)
* Placeholder docs for CSI Migration feature
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Address CR comments and update feature gates
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Add mappings for CSI plugins
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Add sections for AWS and GCE PD migration
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Add docs for Cinder and CSI Migration info
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Clarify scope to volumes with file system
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Change the format of EBS and Cinder CSI Migration sections to follow the GCE template
Signed-off-by: Deep Debroy <ddebroy@docker.com>
* Windows documentation updates for 1.14 (#12929)
* Updated the note to indicate doc work for 1.14
* first attempt at md export from gdoc
* simplifyig
* big attempt
* moving DRAFT windows content to PR for review
* moving content to PR in markdown for review
* updated note tags
* Delete windows-contributing.md
deleting this file as it is already ported to the github contributor guide
* fixed formatting in intro and cluster setup guide
* updating formatting for running containers guide
* rejiggered end of troubleshooting
* fixed minor typos
* Clarified the windows binary download step
* Update _index.md
making updates based on feedback
* Update _index.md
updating ovn-kubernetes docs
* Update _index.md
* Update _index.md
* updating relative docs links
updating all the links to be relative links to /docs
* Update _index.md
* Update _index.md
updates for windows services and ovn-kubernetes
* formatted for correct step numbering
* fix typos
* Update _index.md
updates for flannel PR in troubleshooting
* Update _index.md
* Update _index.md
updating a few sections like roadmap, services, troubleshooting/filing tickets
* Update _index.md
* Update _index.md
* Update _index.md
* Fixed a few whitespace issues
* Update _index.md
* Update _index.md
* Update _index.md
* add section on upgrading CoreDNS (#12909)
* documentation for kubelet resource metrics endpoint (#12934)
* windows docs updates for 1.14 (#13279)
* Delete sample-l2bridge-wincni-config.json
this file is not used anywhere
* Update _index.md
* Update _index.md
* Update _index.md
* Update _index.md
* Update _index.md
* Rename content/en/docs/getting-started-guides/windows/_index.md to content/en/docs/setup/windows/_index.md
moving to new location
* Delete flannel-master-kubectl-get-ds.png
* Delete flannel-master-kubeclt-get-pods.png
* Delete windows-docker-error.png
* Add files via upload
* Rename _index.md to add-windows-nodes.md
* Create _index.md
* Update _index.md
* Update add-windows-nodes.md
* Update add-windows-nodes.md
* Create user-guide-windows-nodes.md
* Create user-guide-windows-containers.md
* Update and rename add-windows-nodes.md to intro-windows-nodes.md
* Update user-guide-windows-containers.md
* Rename intro-windows-nodes.md to intro-windows-in-kubernetes.md
* Update user-guide-windows-nodes.md
* Update user-guide-windows-containers.md
* Update user-guide-windows-containers.md
* Update user-guide-windows-nodes.md
* Update user-guide-windows-containers.md
* Update _index.md
* Update intro-windows-in-kubernetes.md
* Update intro-windows-in-kubernetes.md
fixing the pause image
* Update intro-windows-in-kubernetes.md
changing tables from html to MD
* Update user-guide-windows-nodes.md
converting tables from HTML to MD
* Update intro-windows-in-kubernetes.md
* Update user-guide-windows-nodes.md
* Update user-guide-windows-nodes.md
* Update user-guide-windows-nodes.md
updating the numbering , even though it messes up the notes a little bit. Jim will file a ticket to follow up
* Update user-guide-windows-nodes.md
* update to windows docs for 1.14 (#13322)
* Update intro-windows-in-kubernetes.md
* Update intro-windows-in-kubernetes.md
* Update intro-windows-in-kubernetes.md
* Update intro-windows-in-kubernetes.md
* Update intro-windows-in-kubernetes.md
* Update user-guide-windows-containers.md
* Update user-guide-windows-nodes.md
* Update intro-windows-in-kubernetes.md (#13344)
* server side apply followup (#13321)
* change some parts of serverside apply docs in response to comments
* fix typos and wording
* Update config.toml (#13365)
2019-03-25 22:06:16 +00:00
|
|
|
[`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands/#apply) to create the
|
2023-11-17 19:00:24 +00:00
|
|
|
headless Service and StatefulSet:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-11-17 19:00:24 +00:00
|
|
|
kubectl apply -f https://k8s.io/examples/application/web/web.yaml
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
service/nginx created
|
|
|
|
statefulset.apps/web created
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
The command above creates two Pods, each running an
|
2020-05-25 00:15:30 +00:00
|
|
|
[NGINX](https://www.nginx.com) webserver. Get the `nginx` Service...
|
2016-11-28 22:22:55 +00:00
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get service nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
nginx ClusterIP None <none> 80/TCP 12s
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
...then get the `web` StatefulSet, to verify that both were created successfully:
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get statefulset web
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2024-04-12 07:01:03 +00:00
|
|
|
NAME READY AGE
|
|
|
|
web 2/2 37s
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2023-12-19 17:53:21 +00:00
|
|
|
### Ordered Pod creation
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
A StatefulSet defaults to creating its Pods in a strict order.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
For a StatefulSet with _n_ replicas, when Pods are being deployed, they are
|
|
|
|
created sequentially, ordered from _{0..n-1}_. Examine the output of the
|
2020-05-24 23:32:37 +00:00
|
|
|
`kubectl get` command in the first terminal. Eventually, the output will
|
2016-11-28 22:22:55 +00:00
|
|
|
look like the example below.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# Do not start a new watch;
|
|
|
|
# this should already be running
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
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 19s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 ContainerCreating 0 0s
|
|
|
|
web-1 1/1 Running 0 18s
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Notice that the `web-1` Pod is not launched until the `web-0` Pod is
|
2020-05-25 00:15:30 +00:00
|
|
|
_Running_ (see [Pod Phase](/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase))
|
|
|
|
and _Ready_ (see `type` in [Pod Conditions](/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions)).
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Later in this tutorial you will practice [parallel startup](#parallel-pod-management).
|
|
|
|
|
2022-11-28 02:08:14 +00:00
|
|
|
{{< note >}}
|
|
|
|
To configure the integer ordinal assigned to each Pod in a StatefulSet, see
|
2022-11-28 11:58:57 +00:00
|
|
|
[Start ordinal](/docs/concepts/workloads/controllers/statefulset/#start-ordinal).
|
2022-11-28 02:08:14 +00:00
|
|
|
{{< /note >}}
|
2022-11-09 18:06:03 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Pods in a StatefulSet
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
Pods in a StatefulSet have a unique ordinal index and a stable network identity.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Examining the Pod's ordinal index
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the StatefulSet's Pods:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get pods -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 1m
|
|
|
|
web-1 1/1 Running 0 1m
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
As mentioned in the [StatefulSets](/docs/concepts/workloads/controllers/statefulset/)
|
|
|
|
concept, the Pods in a StatefulSet have a sticky, unique identity. This identity
|
|
|
|
is based on a unique ordinal index that is assigned to each Pod by the
|
2020-05-25 00:15:30 +00:00
|
|
|
StatefulSet {{< glossary_tooltip term_id="controller" text="controller">}}.
|
|
|
|
The Pods' names take the form `<statefulset name>-<ordinal index>`.
|
|
|
|
Since the `web` StatefulSet has two replicas, it creates two Pods, `web-0` and `web-1`.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Using stable network identities
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2016-11-28 22:22:55 +00:00
|
|
|
Each Pod has a stable hostname based on its ordinal index. Use
|
2020-05-24 23:32:37 +00:00
|
|
|
[`kubectl exec`](/docs/reference/generated/kubectl/kubectl-commands/#exec) to execute the
|
2020-05-25 00:15:30 +00:00
|
|
|
`hostname` command in each Pod:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
for i in 0 1; do kubectl exec "web-$i" -- sh -c 'hostname'; done
|
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
web-0
|
|
|
|
web-1
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Use [`kubectl run`](/docs/reference/generated/kubectl/kubectl-commands/#run) to execute
|
|
|
|
a container that provides the `nslookup` command from the `dnsutils` package.
|
|
|
|
Using `nslookup` on the Pods' hostnames, you can examine their in-cluster DNS
|
2020-05-25 00:15:30 +00:00
|
|
|
addresses:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
kubectl run -i --tty --image busybox:1.28 dns-test --restart=Never --rm
|
|
|
|
```
|
|
|
|
which starts a new shell. In that new shell, run:
|
|
|
|
```shell
|
|
|
|
# Run this in the dns-test container shell
|
2016-11-29 19:33:21 +00:00
|
|
|
nslookup web-0.nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
The output is similar to:
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
Server: 10.0.0.10
|
|
|
|
Address 1: 10.0.0.10 kube-dns.kube-system.svc.cluster.local
|
|
|
|
|
|
|
|
Name: web-0.nginx
|
|
|
|
Address 1: 10.244.1.6
|
|
|
|
|
2016-11-29 19:33:21 +00:00
|
|
|
nslookup web-1.nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
Server: 10.0.0.10
|
|
|
|
Address 1: 10.0.0.10 kube-dns.kube-system.svc.cluster.local
|
|
|
|
|
|
|
|
Name: web-1.nginx
|
|
|
|
Address 1: 10.244.2.6
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
(and now exit the container shell: `exit`)
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
The CNAME of the headless service points to SRV records (one for each Pod that
|
|
|
|
is Running and Ready). The SRV records point to A record entries that
|
|
|
|
contain the Pods' IP addresses.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
In one terminal, watch the StatefulSet's Pods:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# Start a new watch
|
|
|
|
# End this watch when you've seen that the delete is finished
|
|
|
|
kubectl get pod --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
In a second terminal, use
|
2020-05-24 23:32:37 +00:00
|
|
|
[`kubectl delete`](/docs/reference/generated/kubectl/kubectl-commands/#delete) to delete all
|
2020-05-25 00:15:30 +00:00
|
|
|
the Pods in the StatefulSet:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete pod -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
pod "web-0" deleted
|
|
|
|
pod "web-1" deleted
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Wait for the StatefulSet to restart them, and for both Pods to transition to
|
2020-05-25 00:15:30 +00:00
|
|
|
Running and Ready:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pod --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 0/1 ContainerCreating 0 0s
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 2s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 ContainerCreating 0 0s
|
|
|
|
web-1 1/1 Running 0 34s
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Use `kubectl exec` and `kubectl run` to view the Pods' hostnames and in-cluster
|
|
|
|
DNS entries. First, view the Pods' hostnames:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
for i in 0 1; do kubectl exec web-$i -- sh -c 'hostname'; done
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
web-0
|
|
|
|
web-1
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
then, run:
|
2023-03-21 08:09:36 +00:00
|
|
|
```shell
|
|
|
|
kubectl run -i --tty --image busybox:1.28 dns-test --restart=Never --rm
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
which starts a new shell.
|
|
|
|
In that new shell, run:
|
|
|
|
```shell
|
|
|
|
# Run this in the dns-test container shell
|
2016-11-29 19:33:21 +00:00
|
|
|
nslookup web-0.nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
The output is similar to:
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
Server: 10.0.0.10
|
|
|
|
Address 1: 10.0.0.10 kube-dns.kube-system.svc.cluster.local
|
|
|
|
|
|
|
|
Name: web-0.nginx
|
|
|
|
Address 1: 10.244.1.7
|
|
|
|
|
2016-11-29 19:33:21 +00:00
|
|
|
nslookup web-1.nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
Server: 10.0.0.10
|
|
|
|
Address 1: 10.0.0.10 kube-dns.kube-system.svc.cluster.local
|
|
|
|
|
|
|
|
Name: web-1.nginx
|
|
|
|
Address 1: 10.244.2.8
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
(and now exit the container shell: `exit`)
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
The Pods' ordinals, hostnames, SRV records, and A record names have not changed,
|
|
|
|
but the IP addresses associated with the Pods may have changed. In the cluster
|
|
|
|
used for this tutorial, they have. This is why it is important not to configure
|
2023-08-28 22:16:42 +00:00
|
|
|
other applications to connect to Pods in a StatefulSet by the IP address
|
|
|
|
of a particular Pod (it is OK to connect to Pods by resolving their hostname).
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
#### Discovery for specific Pods in a StatefulSet
|
2016-12-02 17:53:04 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
If you need to find and connect to the active members of a StatefulSet, you
|
2020-05-25 00:15:30 +00:00
|
|
|
should query the CNAME of the headless Service
|
2020-05-24 23:32:37 +00:00
|
|
|
(`nginx.default.svc.cluster.local`). The SRV records associated with the
|
|
|
|
CNAME will contain only the Pods in the StatefulSet that are Running and
|
2016-11-28 22:22:55 +00:00
|
|
|
Ready.
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
If your application already implements connection logic that tests for
|
|
|
|
liveness and readiness, you can use the SRV records of the Pods (
|
2016-12-02 17:53:04 +00:00
|
|
|
`web-0.nginx.default.svc.cluster.local`,
|
2020-05-24 23:32:37 +00:00
|
|
|
`web-1.nginx.default.svc.cluster.local`), as they are stable, and your
|
|
|
|
application will be able to discover the Pods' addresses when they transition
|
2016-12-02 17:53:04 +00:00
|
|
|
to Running and Ready.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
If your application wants to find any healthy Pod in a StatefulSet,
|
|
|
|
and therefore does not need to track each specific Pod,
|
|
|
|
you could also connect to the IP address of a `type: ClusterIP` Service,
|
|
|
|
backed by the Pods in that StatefulSet. You can use the same Service that
|
|
|
|
tracks the StatefulSet (specified in the `serviceName` of the StatefulSet)
|
|
|
|
or a separate Service that selects the right set of Pods.
|
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Writing to stable storage
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the PersistentVolumeClaims for `web-0` and `web-1`:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get pvc -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
The output is similar to:
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
|
|
|
|
www-web-0 Bound pvc-15c268c7-b507-11e6-932f-42010a800002 1Gi RWO 48s
|
|
|
|
www-web-1 Bound pvc-15c79307-b507-11e6-932f-42010a800002 1Gi RWO 48s
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
The StatefulSet controller created two
|
|
|
|
{{< glossary_tooltip text="PersistentVolumeClaims" term_id="persistent-volume-claim" >}}
|
|
|
|
that are bound to two
|
|
|
|
{{< glossary_tooltip text="PersistentVolumes" term_id="persistent-volume" >}}.
|
|
|
|
|
|
|
|
As the cluster used in this tutorial is configured to dynamically provision PersistentVolumes,
|
|
|
|
the PersistentVolumes were created and bound automatically.
|
|
|
|
|
|
|
|
The NGINX webserver, by default, serves an index file from
|
2020-05-24 23:32:37 +00:00
|
|
|
`/usr/share/nginx/html/index.html`. The `volumeMounts` field in the
|
2020-05-25 00:15:30 +00:00
|
|
|
StatefulSet's `spec` ensures that the `/usr/share/nginx/html` directory is
|
2016-11-29 18:01:38 +00:00
|
|
|
backed by a PersistentVolume.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Write the Pods' hostnames to their `index.html` files and verify that the NGINX
|
2020-05-25 00:15:30 +00:00
|
|
|
webservers serve the hostnames:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
for i in 0 1; do kubectl exec "web-$i" -- sh -c 'echo "$(hostname)" > /usr/share/nginx/html/index.html'; done
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done
|
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
web-0
|
|
|
|
web-1
|
|
|
|
```
|
|
|
|
|
2018-06-25 18:31:22 +00:00
|
|
|
{{< note >}}
|
2020-05-25 00:15:30 +00:00
|
|
|
If you instead see **403 Forbidden** responses for the above curl command,
|
2017-01-17 07:05:32 +00:00
|
|
|
you will need to fix the permissions of the directory mounted by the `volumeMounts`
|
2020-05-25 00:15:30 +00:00
|
|
|
(due to a [bug when using hostPath volumes](https://github.com/kubernetes/kubernetes/issues/2630)),
|
|
|
|
by running:
|
2017-01-17 07:05:32 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
`for i in 0 1; do kubectl exec web-$i -- chmod 755 /usr/share/nginx/html; done`
|
2017-01-17 07:05:32 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
before retrying the `curl` command above.
|
2018-06-25 18:31:22 +00:00
|
|
|
{{< /note >}}
|
2017-01-17 07:05:32 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
In one terminal, watch the StatefulSet's Pods:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# End this watch when you've reached the end of the section.
|
|
|
|
# At the start of "Scaling a StatefulSet" you'll start a new watch.
|
|
|
|
kubectl get pod --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
In a second terminal, delete all of the StatefulSet's Pods:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete pod -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
pod "web-0" deleted
|
|
|
|
pod "web-1" deleted
|
|
|
|
```
|
2020-05-24 23:32:37 +00:00
|
|
|
Examine the output of the `kubectl get` command in the first terminal, and wait
|
2016-11-28 22:22:55 +00:00
|
|
|
for all of the Pods to transition to Running and Ready.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pod --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 0/1 ContainerCreating 0 0s
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 2s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 ContainerCreating 0 0s
|
|
|
|
web-1 1/1 Running 0 34s
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Verify the web servers continue to serve their hostnames:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```
|
2020-05-25 00:15:30 +00:00
|
|
|
for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done
|
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
web-0
|
|
|
|
web-1
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Even though `web-0` and `web-1` were rescheduled, they continue to serve their
|
|
|
|
hostnames because the PersistentVolumes associated with their
|
|
|
|
PersistentVolumeClaims are remounted to their `volumeMounts`. No matter what
|
|
|
|
node `web-0`and `web-1` are scheduled on, their PersistentVolumes will be
|
2017-06-27 16:46:39 +00:00
|
|
|
mounted to the appropriate mount points.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Scaling a StatefulSet
|
2020-05-25 00:15:30 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Scaling a StatefulSet refers to increasing or decreasing the number of replicas
|
|
|
|
(horizontal scaling).
|
2016-12-02 22:26:22 +00:00
|
|
|
This is accomplished by updating the `replicas` field. You can use either
|
2018-04-27 22:02:19 +00:00
|
|
|
[`kubectl scale`](/docs/reference/generated/kubectl/kubectl-commands/#scale) or
|
|
|
|
[`kubectl patch`](/docs/reference/generated/kubectl/kubectl-commands/#patch) to scale a StatefulSet.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Scaling up
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Scaling up means adding more replicas.
|
|
|
|
Provided that your app is able to distribute work across the StatefulSet, the new
|
|
|
|
larger set of Pods can perform more of that work.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
In one terminal window, watch the Pods in the StatefulSet:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# If you already have a watch running, you can continue using that.
|
|
|
|
# Otherwise, start one.
|
|
|
|
# End this watch when there are 5 healthy Pods for the StatefulSet
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
In another terminal window, use `kubectl scale` to scale the number of replicas
|
2020-05-25 00:15:30 +00:00
|
|
|
to 5:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2017-06-27 16:46:39 +00:00
|
|
|
kubectl scale sts web --replicas=5
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web scaled
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Examine the output of the `kubectl get` command in the first terminal, and wait
|
2016-11-28 22:22:55 +00:00
|
|
|
for the three additional Pods to transition to Running and Ready.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pod --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 2h
|
|
|
|
web-1 1/1 Running 0 2h
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
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 19s
|
|
|
|
web-3 0/1 Pending 0 0s
|
|
|
|
web-3 0/1 Pending 0 0s
|
|
|
|
web-3 0/1 ContainerCreating 0 0s
|
|
|
|
web-3 1/1 Running 0 18s
|
|
|
|
web-4 0/1 Pending 0 0s
|
|
|
|
web-4 0/1 Pending 0 0s
|
|
|
|
web-4 0/1 ContainerCreating 0 0s
|
|
|
|
web-4 1/1 Running 0 19s
|
|
|
|
```
|
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
The StatefulSet controller scaled the number of replicas. As with
|
|
|
|
[StatefulSet creation](#ordered-pod-creation), the StatefulSet controller
|
2020-05-24 23:32:37 +00:00
|
|
|
created each Pod sequentially with respect to its ordinal index, and it
|
|
|
|
waited for each Pod's predecessor to be Running and Ready before launching the
|
2016-11-28 22:22:55 +00:00
|
|
|
subsequent Pod.
|
|
|
|
|
2023-12-19 17:53:21 +00:00
|
|
|
### Scaling down
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Scaling down means reducing the number of replicas. For example, you
|
|
|
|
might do this because the level of traffic to a service has decreased,
|
|
|
|
and at the current scale there are idle resources.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
In one terminal, watch the StatefulSet's Pods:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# End this watch when there are only 3 Pods for the StatefulSet
|
|
|
|
kubectl get pod --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
In another terminal, use `kubectl patch` to scale the StatefulSet back down to
|
2020-05-25 00:15:30 +00:00
|
|
|
three replicas:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2017-06-27 16:46:39 +00:00
|
|
|
kubectl patch sts web -p '{"spec":{"replicas":3}}'
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web patched
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Wait for `web-4` and `web-3` to transition to Terminating.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 3h
|
|
|
|
web-1 1/1 Running 0 3h
|
|
|
|
web-2 1/1 Running 0 55s
|
|
|
|
web-3 1/1 Running 0 36s
|
|
|
|
web-4 0/1 ContainerCreating 0 18s
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-4 1/1 Running 0 19s
|
|
|
|
web-4 1/1 Terminating 0 24s
|
|
|
|
web-4 1/1 Terminating 0 24s
|
|
|
|
web-3 1/1 Terminating 0 42s
|
|
|
|
web-3 1/1 Terminating 0 42s
|
|
|
|
```
|
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Ordered Pod termination
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
The control plane deleted one Pod at a time, in reverse order with respect
|
|
|
|
to its ordinal index, and it waited for each Pod to be completely shut down
|
|
|
|
before deleting the next one.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the StatefulSet's PersistentVolumeClaims:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get pvc -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
|
|
|
|
www-web-0 Bound pvc-15c268c7-b507-11e6-932f-42010a800002 1Gi RWO 13h
|
|
|
|
www-web-1 Bound pvc-15c79307-b507-11e6-932f-42010a800002 1Gi RWO 13h
|
|
|
|
www-web-2 Bound pvc-e1125b27-b508-11e6-932f-42010a800002 1Gi RWO 13h
|
|
|
|
www-web-3 Bound pvc-e1176df6-b508-11e6-932f-42010a800002 1Gi RWO 13h
|
|
|
|
www-web-4 Bound pvc-e11bb5f8-b508-11e6-932f-42010a800002 1Gi RWO 13h
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
There are still five PersistentVolumeClaims and five PersistentVolumes.
|
2023-08-28 22:16:42 +00:00
|
|
|
When exploring a Pod's [stable storage](#writing-to-stable-storage), you saw that
|
|
|
|
the PersistentVolumes mounted to the Pods of a StatefulSet are not deleted when the
|
|
|
|
StatefulSet's Pods are deleted. This is still true when Pod deletion is caused by
|
|
|
|
scaling the StatefulSet down.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2017-06-27 16:46:39 +00:00
|
|
|
## Updating StatefulSets
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
The StatefulSet controller supports automated updates. The
|
2020-05-24 23:32:37 +00:00
|
|
|
strategy used is determined by the `spec.updateStrategy` field of the
|
2023-12-22 11:42:31 +00:00
|
|
|
StatefulSet API object. This feature can be used to upgrade the container
|
2020-05-24 23:32:37 +00:00
|
|
|
images, resource requests and/or limits, labels, and annotations of the Pods in a
|
2023-12-22 11:42:31 +00:00
|
|
|
StatefulSet.
|
2018-07-08 10:34:18 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
There are two valid update strategies, `RollingUpdate` (the default) and
|
|
|
|
`OnDelete`.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### RollingUpdate {#rolling-update}
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
The `RollingUpdate` update strategy will update all Pods in a StatefulSet, in
|
2017-06-27 16:46:39 +00:00
|
|
|
reverse ordinal order, while respecting the StatefulSet guarantees.
|
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
You can split updates to a StatefulSet that uses the `RollingUpdate` strategy
|
|
|
|
into _partitions_, by specifying `.spec.updateStrategy.rollingUpdate.partition`.
|
|
|
|
You'll practice that later in this tutorial.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
First, try a simple rolling update.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
In one terminal window, patch the `web` StatefulSet to change the container
|
2020-05-25 00:15:30 +00:00
|
|
|
image again:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2024-06-04 07:40:02 +00:00
|
|
|
kubectl patch statefulset web --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"registry.k8s.io/nginx-slim:0.24"}]'
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web patched
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
In another terminal, watch the Pods in the StatefulSet:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# End this watch when the rollout is complete
|
|
|
|
#
|
|
|
|
# If you're not sure, leave it running one more minute
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-01-31 12:50:43 +00:00
|
|
|
The output is similar to:
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 7m
|
|
|
|
web-1 1/1 Running 0 7m
|
|
|
|
web-2 1/1 Running 0 8m
|
|
|
|
web-2 1/1 Terminating 0 8m
|
|
|
|
web-2 1/1 Terminating 0 8m
|
|
|
|
web-2 0/1 Terminating 0 8m
|
|
|
|
web-2 0/1 Terminating 0 8m
|
|
|
|
web-2 0/1 Terminating 0 8m
|
|
|
|
web-2 0/1 Terminating 0 8m
|
|
|
|
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 19s
|
|
|
|
web-1 1/1 Terminating 0 8m
|
|
|
|
web-1 0/1 Terminating 0 8m
|
|
|
|
web-1 0/1 Terminating 0 8m
|
|
|
|
web-1 0/1 Terminating 0 8m
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 ContainerCreating 0 0s
|
|
|
|
web-1 1/1 Running 0 6s
|
|
|
|
web-0 1/1 Terminating 0 7m
|
|
|
|
web-0 1/1 Terminating 0 7m
|
|
|
|
web-0 0/1 Terminating 0 7m
|
|
|
|
web-0 0/1 Terminating 0 7m
|
|
|
|
web-0 0/1 Terminating 0 7m
|
|
|
|
web-0 0/1 Terminating 0 7m
|
|
|
|
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 10s
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
The Pods in the StatefulSet are updated in reverse ordinal order. The
|
|
|
|
StatefulSet controller terminates each Pod, and waits for it to transition to Running and
|
|
|
|
Ready prior to updating the next Pod. Note that, even though the StatefulSet
|
|
|
|
controller will not proceed to update the next Pod until its ordinal successor
|
|
|
|
is Running and Ready, it will restore any Pod that fails during the update to
|
2023-12-22 11:42:31 +00:00
|
|
|
that Pod's existing version.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Pods that have already received the update will be restored to the updated version,
|
|
|
|
and Pods that have not yet received the update will be restored to the previous
|
|
|
|
version. In this way, the controller attempts to continue to keep the application
|
|
|
|
healthy and the update consistent in the presence of intermittent failures.
|
|
|
|
|
|
|
|
Get the Pods to view their container images:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
for p in 0 1 2; do kubectl get pod "web-$p" --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'; echo; done
|
|
|
|
```
|
|
|
|
```
|
2024-06-04 07:40:02 +00:00
|
|
|
registry.k8s.io/nginx-slim:0.24
|
|
|
|
registry.k8s.io/nginx-slim:0.24
|
|
|
|
registry.k8s.io/nginx-slim:0.24
|
2018-05-05 16:00:51 +00:00
|
|
|
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
All the Pods in the StatefulSet are now running the previous container image.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
{{< note >}}
|
|
|
|
You can also use `kubectl rollout status sts/<name>` to view
|
|
|
|
the status of a rolling update to a StatefulSet
|
|
|
|
{{< /note >}}
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
#### Staging an update
|
2020-05-25 00:15:30 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
You can split updates to a StatefulSet that uses the `RollingUpdate` strategy
|
|
|
|
into _partitions_, by specifying `.spec.updateStrategy.rollingUpdate.partition`.
|
|
|
|
|
|
|
|
For more context, you can read [Partitioned rolling updates](/docs/concepts/workloads/controllers/statefulset/#partitions)
|
|
|
|
in the StatefulSet concept page.
|
|
|
|
|
|
|
|
You can stage an update to a StatefulSet by using the `partition` field within
|
|
|
|
`.spec.updateStrategy.rollingUpdate`.
|
|
|
|
For this update, you will keep the existing Pods in the StatefulSet
|
|
|
|
unchanged whilst you change the pod template for the StatefulSet.
|
|
|
|
Then you - or, outside of a tutorial, some external automation - can
|
|
|
|
trigger that prepared update.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
First, patch the `web` StatefulSet to add a partition to the `updateStrategy` field:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-22 11:42:31 +00:00
|
|
|
# The value of "partition" determines which ordinals a change applies to
|
|
|
|
# Make sure to use a number bigger than the last ordinal for the
|
|
|
|
# StatefulSet
|
2017-06-27 16:46:39 +00:00
|
|
|
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":3}}}}'
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web patched
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
Patch the StatefulSet again to change the container image that this
|
|
|
|
StatefulSet uses:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2024-06-04 07:40:02 +00:00
|
|
|
kubectl patch statefulset web --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"registry.k8s.io/nginx-slim:0.21"}]'
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web patched
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Delete a Pod in the StatefulSet:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
kubectl delete pod web-2
|
|
|
|
```
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
pod "web-2" deleted
|
|
|
|
```
|
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
Wait for the replacement `web-2` Pod to be Running and Ready:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# End the watch when you see that web-2 is healthy
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 4m
|
|
|
|
web-1 1/1 Running 0 4m
|
|
|
|
web-2 0/1 ContainerCreating 0 11s
|
|
|
|
web-2 1/1 Running 0 18s
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the Pod's container image:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
kubectl get pod web-2 --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'
|
|
|
|
```
|
|
|
|
```
|
2024-06-04 07:40:02 +00:00
|
|
|
registry.k8s.io/nginx-slim:0.24
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Notice that, even though the update strategy is `RollingUpdate` the StatefulSet
|
2023-12-22 11:42:31 +00:00
|
|
|
restored the Pod with the original container image. This is because the
|
2020-05-24 23:32:37 +00:00
|
|
|
ordinal of the Pod is less than the `partition` specified by the
|
2017-06-27 16:46:39 +00:00
|
|
|
`updateStrategy`.
|
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
#### Rolling out a canary
|
2020-05-25 00:15:30 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
You're now going to try a [canary rollout](https://glossary.cncf.io/canary-deployment/)
|
|
|
|
of that staged change.
|
|
|
|
|
|
|
|
You can roll out a canary (to test the modified template) by decrementing the `partition`
|
2017-06-27 16:46:39 +00:00
|
|
|
you specified [above](#staging-an-update).
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Patch the StatefulSet to decrement the partition:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# The value of "partition" should match the highest existing ordinal for
|
|
|
|
# the StatefulSet
|
2017-06-27 16:46:39 +00:00
|
|
|
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":2}}}}'
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web patched
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
The control plane triggers replacement for `web-2` (implemented by
|
|
|
|
a graceful **delete** followed by creating a new Pod once the deletion
|
|
|
|
is complete).
|
|
|
|
Wait for the new `web-2` Pod to be Running and Ready.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 4m
|
|
|
|
web-1 1/1 Running 0 4m
|
|
|
|
web-2 0/1 ContainerCreating 0 11s
|
|
|
|
web-2 1/1 Running 0 18s
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the Pod's container:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
kubectl get pod web-2 --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'
|
|
|
|
```
|
|
|
|
```
|
2024-06-04 07:40:02 +00:00
|
|
|
registry.k8s.io/nginx-slim:0.21
|
2018-05-05 16:00:51 +00:00
|
|
|
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
When you changed the `partition`, the StatefulSet controller automatically
|
|
|
|
updated the `web-2` Pod because the Pod's ordinal was greater than or equal to
|
2017-06-27 16:46:39 +00:00
|
|
|
the `partition`.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Delete the `web-1` Pod:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
kubectl delete pod web-1
|
|
|
|
```
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
pod "web-1" deleted
|
|
|
|
```
|
|
|
|
|
|
|
|
Wait for the `web-1` Pod to be Running and Ready.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
The output is similar to:
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 6m
|
|
|
|
web-1 0/1 Terminating 0 6m
|
|
|
|
web-2 1/1 Running 0 2m
|
|
|
|
web-1 0/1 Terminating 0 6m
|
|
|
|
web-1 0/1 Terminating 0 6m
|
|
|
|
web-1 0/1 Terminating 0 6m
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 Pending 0 0s
|
|
|
|
web-1 0/1 ContainerCreating 0 0s
|
|
|
|
web-1 1/1 Running 0 18s
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the `web-1` Pod's container image:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
kubectl get pod web-1 --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'
|
|
|
|
```
|
|
|
|
```
|
2024-06-04 07:40:02 +00:00
|
|
|
registry.k8s.io/nginx-slim:0.24
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
2020-05-25 00:15:30 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
`web-1` was restored to its original configuration because the Pod's ordinal
|
|
|
|
was less than the partition. When a partition is specified, all Pods with an
|
|
|
|
ordinal that is greater than or equal to the partition will be updated when the
|
|
|
|
StatefulSet's `.spec.template` is updated. If a Pod that has an ordinal less
|
|
|
|
than the partition is deleted or otherwise terminated, it will be restored to
|
2017-06-27 16:46:39 +00:00
|
|
|
its original configuration.
|
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
#### Phased roll outs
|
2020-05-25 00:15:30 +00:00
|
|
|
|
2017-06-27 16:46:39 +00:00
|
|
|
You can perform a phased roll out (e.g. a linear, geometric, or exponential
|
2020-05-24 23:32:37 +00:00
|
|
|
roll out) using a partitioned rolling update in a similar manner to how you
|
|
|
|
rolled out a [canary](#rolling-out-a-canary). To perform a phased roll out, set
|
|
|
|
the `partition` to the ordinal at which you want the controller to pause the
|
|
|
|
update.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
The partition is currently set to `2`. Set the partition to `0`:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":0}}}}'
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web patched
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Wait for all of the Pods in the StatefulSet to become Running and Ready.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
The output is similar to:
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 3m
|
|
|
|
web-1 0/1 ContainerCreating 0 11s
|
|
|
|
web-2 1/1 Running 0 2m
|
|
|
|
web-1 1/1 Running 0 18s
|
|
|
|
web-0 1/1 Terminating 0 3m
|
|
|
|
web-0 1/1 Terminating 0 3m
|
|
|
|
web-0 0/1 Terminating 0 3m
|
|
|
|
web-0 0/1 Terminating 0 3m
|
|
|
|
web-0 0/1 Terminating 0 3m
|
|
|
|
web-0 0/1 Terminating 0 3m
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the container image details for the Pods in the StatefulSet:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
for p in 0 1 2; do kubectl get pod "web-$p" --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'; echo; done
|
|
|
|
```
|
|
|
|
```
|
2024-06-04 07:40:02 +00:00
|
|
|
registry.k8s.io/nginx-slim:0.21
|
|
|
|
registry.k8s.io/nginx-slim:0.21
|
|
|
|
registry.k8s.io/nginx-slim:0.21
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
By moving the `partition` to `0`, you allowed the StatefulSet to
|
2017-06-27 16:46:39 +00:00
|
|
|
continue the update process.
|
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### OnDelete {#on-delete}
|
Release 1.8 (#5659)
* GC now supports non-core resources
* Add two examples about how to analysis audits of kube-apiserver (#4264)
* Deprecate system:nodes binding
* [1.8] StatefulSet `initialized` annotation is now ignored.
* inits the kubeadm upgrade docs
addresses kubernetes/kubernetes.github.io/issues/4689
* adds kubeadm upgrade cmd to ToC
addresses kubernetes/kubernetes.github.io/issues/4689
* add workload placement docs
* ScaleIO - document udpate for 1.8
* Add documentation on storageClass.mountOptions and PV.mountOptions (#5254)
* Add documentation on storageClass.mountOptions and PV.mountOptions
* convert notes into callouts
* Add docs for CustomResource validation
add info about supported fields
* advanced audit beta features (#5300)
* Update job workload doc with backoff failure policy (#5319)
Add to the Jobs documentation how to use the new backoffLimit field that
limit the number of Pod failure before considering the Job as failed.
* Documented additional AWS Service annotations (#4864)
* Add device plugin doc under concepts/cluster-administration. (#5261)
* Add device plugin doc under concepts/cluster-administration.
* Update device-plugins.md
* Update device-plugins.md
Add meta description. Fix typo. Change bare metal deployment to manual deployment.
* Update device-plugins.md
Fix typo again.
* Update page.version. (#5341)
* Add documentation on storageClass.reclaimPolicy (#5171)
* [Advanced audit] use new herf for audit-api (#5349)
This tag contains all the changes in v1beta1 version. Update it now.
* Added documentation around creating the InitializerConfiguration for the persistent volume label controller in the cloud-controller-manager (#5255)
* Documentation for kubectl plugins (#5294)
* Documentation for kubectl plugins
* Update kubectl-plugins.md
* Update kubectl-plugins.md
* Updated CPU manager docs to match implementation. (#5332)
* Noted limitation of alpha static cpumanager.
* Updated CPU manager docs to match implementation.
- Removed references to CPU pressure node condition and evictions.
- Added note about new --cpu-manager-reconcile-period flag.
- Added note about node allocatable requirements for static policy.
- Noted limitation of alpha static cpumanager.
* Move cpu-manager task link to rsc mgmt section.
* init containers annotation removed in 1.8 (#5390)
* Add documentation for TaintNodesByCondition (#5352)
* Add documentation for TaintNodesByCondition
* Update nodes.md
* Update taint-and-toleration.md
* Update daemonset.md
* Update nodes.md
* Update taint-and-toleration.md
* Update daemonset.md
* Fix deployments (#5421)
* Document extended resources and OIR deprecation. (#5399)
* Document extended resources and OIR deprecation.
* Updated extended resources doc per reviews.
* reverts extra spacing in _data/tasks.yml
* addresses `kubeadm upgrade` review comments
Feedback from @chenopis, @luxas, and @steveperry-53 addressed with this commit
* HugePages documentation (#5419)
* Update cpu-management-policies.md (#5407)
Fixed the bad link.
Modified "cpu" to "CPU".
Added more 'yaml' as supplement.
* Update RBAC docs for v1 (#5445)
* Add user docs for pod priority and preemption (#5328)
* Add user docs for pod priority and preemption
* Update pod-priority-preemption.md
* More updates
* Update docs/admin/kubeadm.md for 1.8 (#5440)
- Made a couple of minor wording changes (not strictly 1.8 related).
- Did some reformatting (not strictly 1.8 related).
- Updated references to the default token TTL (was infinite, now 24 hours).
- Documented the new `--discovery-token-ca-cert-hash` and `--discovery-token-unsafe-skip-ca-verification` flags for `kubeadm join`.
- Added references to the new `--discovery-token-ca-cert-hash` flag in all the default examples.
- Added a new _Security model_ section that describes the security tradeoffs of the various discovery modes.
- Documented the new `--groups` flag for `kubeadm token create`.
- Added a note of caution under _Automating kubeadm_ that references the _Security model_ section.
- Updated the component version table to drop 1.6 and add 1.8.
- Update `_data/reference.yml` to try to get the sidebar fixed up and more consistent with `kubefed`.
* Update StatefulSet Basics for 1.8 release (#5398)
* addresses `kubeadm upgrade` review comments
2nd iteration review comments by @luxas
* adds kubelet upgrade section to kubeadm upgrade
* Fix a bulleted list on docs/admin/kubeadm.md. (#5458)
I updated this doc yesterday and I was absolutely sure I fixed this, but I just saw that this commit got lost somehow.
This was introduced recently in https://github.com/kubernetes/kubernetes.github.io/pull/5440.
* Clarify the API to check for device plugins
* Moving Flexvolume to separate out-of-tree section
* addresses `kubeadm upgrade` review comments
CC: @luxas
* fixes kubeadm upgrade index
* Update Stackdriver Logging documentation (#5495)
* Re-update WordPress and MySQL PV doc to use apps/v1beta2 APIs (#5526)
* Update statefulset concepts doc to use apps/v1beta2 APIs (#5420)
* add document on kubectl's behavior regarding initializers (#5505)
* Update docs/admin/kubeadm.md to cover self-hosting in 1.8. (#5497)
This is a new beta feature in 1.8.
* Update kubectl patch doc to use apps/v1beta2 APIs (#5422)
* [1.8] Update "Run Applications" tasks to apps/v1beta2. (#5525)
* Update replicated stateful application task for 1.8.
* Update single instance stateful app task for 1.8.
* Update stateless app task for 1.8.
* Update kubectl patch task for 1.8.
* fix the link of persistent storage (#5515)
* update the admission-controllers.md index.md what-is-kubernetes.md link
* fix the link of persistent storage
* Add quota support for local ephemeral storage (#5493)
* Add quota support for local ephemeral storage
update the doc to this alpha feature
* Update resource-quotas.md
* Updated Deployments concepts doc (#5491)
* Updated Deployments concepts doc
* Addressed comments
* Addressed more comments
* Modify allocatable storage to ephemeral-storage (#5490)
Update the doc to use ephemeral-storage instead of storage
* Revamped concepts doc for ReplicaSet (#5463)
* Revamped concepts doc for ReplicaSet
* Minor changes to call out specific versions for selector defaulting and
immutability
* Addressed doc review comments
* Remove petset documentations (#5395)
* Update docs to use batch/v1beta1 cronjobs (#5475)
* add federation job doc (#5485)
* add federation job doc
* Update job.md
Edits for clarity and consistency
* Update job.md
Fixed a typo
* update DaemonSet concept for 1.8 release (#5397)
* update DaemonSet concept for 1.8 release
* Update daemonset.md
Fix typo. than -> then
* Update bootstrap tokens doc for 1.8. (#5479)
* Update bootstrap tokens doc for 1.8.
This has some changes I missed when I was updating the main kubeadm documention:
- Bootstrap tokens are now beta, not alpha (https://github.com/kubernetes/features/issues/130)
- The apiserver flag to enable the authenticator changedin 1.8 (https://github.com/kubernetes/kubernetes/pull/51198)
- Added `auth-extra-groups` documentaion (https://github.com/kubernetes/kubernetes/pull/50933)
- Updated the _Token Management with `kubeadm`_ section to link to the main kubeadm docs, since it was just duplicated information.
* Update bootstrap-tokens.md
* Updated the Cassandra tutorial to use apps/v1beta2 (#5548)
* add docs for AllowPrivilegeEscalation (#5448)
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
* Add local ephemeral storage alpha feature in managing compute resource (#5522)
* Add local ephemeral storage alpha feature in managing compute resource
Since 1.8, we add the local ephemeral storage alpha feature as one
resource type to manage. Add this feature into the doc.
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Added documentation for Metrics Server (#5560)
* authorization: improve authorization debugging docs (#5549)
* Document mount propagation (#5544)
* Update /docs/setup/independent/create-cluster-kubeadm.md for 1.8. (#5524)
This introduction needed a couple of small tweaks to cover the `--discovery-token-ca-cert-hash` flag added in https://github.com/kubernetes/kubernetes/pull/49520 and some version bumps.
* Add task doc for alpha dynamic kubelet configuration (#5523)
* Fix input/output of selfsubjectaccess review (#5593)
* Add docs for implementing resize (#5528)
* Add docs for implementing resize
* Update admission-controllers.md
* Added link to PVC section
* minor typo fixes
* Update NetworkPolicy concept guide with egress and CIDR changes (#5529)
* update zookeeper tutorial for 1.8 release
* add doc for hostpath type (#5503)
* Federated Hpa feature doc (#5487)
* Federated Hpa feature doc
* Federated Hpa feature doc review fixes
* Update hpa.md
* Update hpa.md
* update cloud controller manager docs for v1.8
* Update cronjob with defaults information (#5556)
* Kubernetes 1.8 reference docs (#5632)
* Kubernetes 1.8 reference docs
* Kubectl reference docs for 1.8
* Update side bar with 1.8 kubectl and api ref docs links
* remove petset.md
* update on state of HostAlias in 1.8 with hostNetwork Pod support (#5644)
* Fix cron job deletion section (#5655)
* update imported docs (#5656)
* Add documentation for certificate rotation. (#5639)
* Link to using kubeadm page
* fix the command output
fix the command output
* fix typo in api/resources reference: "Worloads"
* Add documentation for certificate rotation.
* Create TOC entry for cloud controller manager. (#5662)
* Updates for new versions of API types
* Followup 5655: fix link to garbage collection (#5666)
* Temporarily redirect resources-reference to api-reference. (#5668)
* Update config for 1.8 release. (#5661)
* Update config for 1.8 release.
* Address reviewer comments.
* Switch references in HPA docs from alpha to beta (#5671)
The HPA docs still referenced the alpha version. This switches them to
talk about v2beta1, which is the appropriate version for Kubernetes 1.8
* Deprecate openstack heat (#5670)
* Fix typo in pod preset conflict example
Move container port definition to the correct line.
* Highlight openstack-heat provider deprecation
The openstack-heat provider for kube-up is being deprecated and will be
removed in a future release.
* Temporarily fix broken links by redirecting. (#5672)
* Fix broken links. (#5675)
* Fix render of code block (#5674)
* Fix broken links. (#5677)
* Add a small note about auto-bootstrapped CSR ClusterRoles (#5660)
* Update kubeadm install doc for v1.8 (#5676)
* add draft workloads api content for 1.8 (#5650)
* add draft workloads api content for 1.8
* edits per review, add tables, for 1.8 workloads api doc
* fix typo
* Minor fixes to kubeadm 1.8 upgrade guide. (#5678)
- The kubelet upgrade instructions should be done on every host, not
just worker nodes.
- We should just upgrade all packages, instead of calling out kubelet
specifically. This will also upgrade kubectl, kubeadm, and
kubernetes-cni, if installed.
- Draining nodes should also ignore daemonsets, and master errors can be
ignored.
- Make sure that the new kubeadm download is chmoded correctly.
- Add a step to run `kubeadm version` to verify after downloading.
- Manually approve new kubelet CSRs if rotation is enabled (known issue).
* Release 1.8 (#5680)
* Fix versions for 1.8 API ref docs
* Updates for 1.8 kubectl reference docs
* Kubeadm /docs/admin/kubeadm.md cleanup, editing. (#5681)
* Update docs/admin/kubeadm.md (mostly 1.8 related).
This is Fabrizio's work, which I'm committing along with my edits (in a commit on top of this).
* A few of my own edits to clarify and clean up some Markdown.
2017-09-29 04:46:51 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
You select this update strategy for a StatefulSet by setting the
|
Release 1.8 (#5659)
* GC now supports non-core resources
* Add two examples about how to analysis audits of kube-apiserver (#4264)
* Deprecate system:nodes binding
* [1.8] StatefulSet `initialized` annotation is now ignored.
* inits the kubeadm upgrade docs
addresses kubernetes/kubernetes.github.io/issues/4689
* adds kubeadm upgrade cmd to ToC
addresses kubernetes/kubernetes.github.io/issues/4689
* add workload placement docs
* ScaleIO - document udpate for 1.8
* Add documentation on storageClass.mountOptions and PV.mountOptions (#5254)
* Add documentation on storageClass.mountOptions and PV.mountOptions
* convert notes into callouts
* Add docs for CustomResource validation
add info about supported fields
* advanced audit beta features (#5300)
* Update job workload doc with backoff failure policy (#5319)
Add to the Jobs documentation how to use the new backoffLimit field that
limit the number of Pod failure before considering the Job as failed.
* Documented additional AWS Service annotations (#4864)
* Add device plugin doc under concepts/cluster-administration. (#5261)
* Add device plugin doc under concepts/cluster-administration.
* Update device-plugins.md
* Update device-plugins.md
Add meta description. Fix typo. Change bare metal deployment to manual deployment.
* Update device-plugins.md
Fix typo again.
* Update page.version. (#5341)
* Add documentation on storageClass.reclaimPolicy (#5171)
* [Advanced audit] use new herf for audit-api (#5349)
This tag contains all the changes in v1beta1 version. Update it now.
* Added documentation around creating the InitializerConfiguration for the persistent volume label controller in the cloud-controller-manager (#5255)
* Documentation for kubectl plugins (#5294)
* Documentation for kubectl plugins
* Update kubectl-plugins.md
* Update kubectl-plugins.md
* Updated CPU manager docs to match implementation. (#5332)
* Noted limitation of alpha static cpumanager.
* Updated CPU manager docs to match implementation.
- Removed references to CPU pressure node condition and evictions.
- Added note about new --cpu-manager-reconcile-period flag.
- Added note about node allocatable requirements for static policy.
- Noted limitation of alpha static cpumanager.
* Move cpu-manager task link to rsc mgmt section.
* init containers annotation removed in 1.8 (#5390)
* Add documentation for TaintNodesByCondition (#5352)
* Add documentation for TaintNodesByCondition
* Update nodes.md
* Update taint-and-toleration.md
* Update daemonset.md
* Update nodes.md
* Update taint-and-toleration.md
* Update daemonset.md
* Fix deployments (#5421)
* Document extended resources and OIR deprecation. (#5399)
* Document extended resources and OIR deprecation.
* Updated extended resources doc per reviews.
* reverts extra spacing in _data/tasks.yml
* addresses `kubeadm upgrade` review comments
Feedback from @chenopis, @luxas, and @steveperry-53 addressed with this commit
* HugePages documentation (#5419)
* Update cpu-management-policies.md (#5407)
Fixed the bad link.
Modified "cpu" to "CPU".
Added more 'yaml' as supplement.
* Update RBAC docs for v1 (#5445)
* Add user docs for pod priority and preemption (#5328)
* Add user docs for pod priority and preemption
* Update pod-priority-preemption.md
* More updates
* Update docs/admin/kubeadm.md for 1.8 (#5440)
- Made a couple of minor wording changes (not strictly 1.8 related).
- Did some reformatting (not strictly 1.8 related).
- Updated references to the default token TTL (was infinite, now 24 hours).
- Documented the new `--discovery-token-ca-cert-hash` and `--discovery-token-unsafe-skip-ca-verification` flags for `kubeadm join`.
- Added references to the new `--discovery-token-ca-cert-hash` flag in all the default examples.
- Added a new _Security model_ section that describes the security tradeoffs of the various discovery modes.
- Documented the new `--groups` flag for `kubeadm token create`.
- Added a note of caution under _Automating kubeadm_ that references the _Security model_ section.
- Updated the component version table to drop 1.6 and add 1.8.
- Update `_data/reference.yml` to try to get the sidebar fixed up and more consistent with `kubefed`.
* Update StatefulSet Basics for 1.8 release (#5398)
* addresses `kubeadm upgrade` review comments
2nd iteration review comments by @luxas
* adds kubelet upgrade section to kubeadm upgrade
* Fix a bulleted list on docs/admin/kubeadm.md. (#5458)
I updated this doc yesterday and I was absolutely sure I fixed this, but I just saw that this commit got lost somehow.
This was introduced recently in https://github.com/kubernetes/kubernetes.github.io/pull/5440.
* Clarify the API to check for device plugins
* Moving Flexvolume to separate out-of-tree section
* addresses `kubeadm upgrade` review comments
CC: @luxas
* fixes kubeadm upgrade index
* Update Stackdriver Logging documentation (#5495)
* Re-update WordPress and MySQL PV doc to use apps/v1beta2 APIs (#5526)
* Update statefulset concepts doc to use apps/v1beta2 APIs (#5420)
* add document on kubectl's behavior regarding initializers (#5505)
* Update docs/admin/kubeadm.md to cover self-hosting in 1.8. (#5497)
This is a new beta feature in 1.8.
* Update kubectl patch doc to use apps/v1beta2 APIs (#5422)
* [1.8] Update "Run Applications" tasks to apps/v1beta2. (#5525)
* Update replicated stateful application task for 1.8.
* Update single instance stateful app task for 1.8.
* Update stateless app task for 1.8.
* Update kubectl patch task for 1.8.
* fix the link of persistent storage (#5515)
* update the admission-controllers.md index.md what-is-kubernetes.md link
* fix the link of persistent storage
* Add quota support for local ephemeral storage (#5493)
* Add quota support for local ephemeral storage
update the doc to this alpha feature
* Update resource-quotas.md
* Updated Deployments concepts doc (#5491)
* Updated Deployments concepts doc
* Addressed comments
* Addressed more comments
* Modify allocatable storage to ephemeral-storage (#5490)
Update the doc to use ephemeral-storage instead of storage
* Revamped concepts doc for ReplicaSet (#5463)
* Revamped concepts doc for ReplicaSet
* Minor changes to call out specific versions for selector defaulting and
immutability
* Addressed doc review comments
* Remove petset documentations (#5395)
* Update docs to use batch/v1beta1 cronjobs (#5475)
* add federation job doc (#5485)
* add federation job doc
* Update job.md
Edits for clarity and consistency
* Update job.md
Fixed a typo
* update DaemonSet concept for 1.8 release (#5397)
* update DaemonSet concept for 1.8 release
* Update daemonset.md
Fix typo. than -> then
* Update bootstrap tokens doc for 1.8. (#5479)
* Update bootstrap tokens doc for 1.8.
This has some changes I missed when I was updating the main kubeadm documention:
- Bootstrap tokens are now beta, not alpha (https://github.com/kubernetes/features/issues/130)
- The apiserver flag to enable the authenticator changedin 1.8 (https://github.com/kubernetes/kubernetes/pull/51198)
- Added `auth-extra-groups` documentaion (https://github.com/kubernetes/kubernetes/pull/50933)
- Updated the _Token Management with `kubeadm`_ section to link to the main kubeadm docs, since it was just duplicated information.
* Update bootstrap-tokens.md
* Updated the Cassandra tutorial to use apps/v1beta2 (#5548)
* add docs for AllowPrivilegeEscalation (#5448)
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
* Add local ephemeral storage alpha feature in managing compute resource (#5522)
* Add local ephemeral storage alpha feature in managing compute resource
Since 1.8, we add the local ephemeral storage alpha feature as one
resource type to manage. Add this feature into the doc.
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Added documentation for Metrics Server (#5560)
* authorization: improve authorization debugging docs (#5549)
* Document mount propagation (#5544)
* Update /docs/setup/independent/create-cluster-kubeadm.md for 1.8. (#5524)
This introduction needed a couple of small tweaks to cover the `--discovery-token-ca-cert-hash` flag added in https://github.com/kubernetes/kubernetes/pull/49520 and some version bumps.
* Add task doc for alpha dynamic kubelet configuration (#5523)
* Fix input/output of selfsubjectaccess review (#5593)
* Add docs for implementing resize (#5528)
* Add docs for implementing resize
* Update admission-controllers.md
* Added link to PVC section
* minor typo fixes
* Update NetworkPolicy concept guide with egress and CIDR changes (#5529)
* update zookeeper tutorial for 1.8 release
* add doc for hostpath type (#5503)
* Federated Hpa feature doc (#5487)
* Federated Hpa feature doc
* Federated Hpa feature doc review fixes
* Update hpa.md
* Update hpa.md
* update cloud controller manager docs for v1.8
* Update cronjob with defaults information (#5556)
* Kubernetes 1.8 reference docs (#5632)
* Kubernetes 1.8 reference docs
* Kubectl reference docs for 1.8
* Update side bar with 1.8 kubectl and api ref docs links
* remove petset.md
* update on state of HostAlias in 1.8 with hostNetwork Pod support (#5644)
* Fix cron job deletion section (#5655)
* update imported docs (#5656)
* Add documentation for certificate rotation. (#5639)
* Link to using kubeadm page
* fix the command output
fix the command output
* fix typo in api/resources reference: "Worloads"
* Add documentation for certificate rotation.
* Create TOC entry for cloud controller manager. (#5662)
* Updates for new versions of API types
* Followup 5655: fix link to garbage collection (#5666)
* Temporarily redirect resources-reference to api-reference. (#5668)
* Update config for 1.8 release. (#5661)
* Update config for 1.8 release.
* Address reviewer comments.
* Switch references in HPA docs from alpha to beta (#5671)
The HPA docs still referenced the alpha version. This switches them to
talk about v2beta1, which is the appropriate version for Kubernetes 1.8
* Deprecate openstack heat (#5670)
* Fix typo in pod preset conflict example
Move container port definition to the correct line.
* Highlight openstack-heat provider deprecation
The openstack-heat provider for kube-up is being deprecated and will be
removed in a future release.
* Temporarily fix broken links by redirecting. (#5672)
* Fix broken links. (#5675)
* Fix render of code block (#5674)
* Fix broken links. (#5677)
* Add a small note about auto-bootstrapped CSR ClusterRoles (#5660)
* Update kubeadm install doc for v1.8 (#5676)
* add draft workloads api content for 1.8 (#5650)
* add draft workloads api content for 1.8
* edits per review, add tables, for 1.8 workloads api doc
* fix typo
* Minor fixes to kubeadm 1.8 upgrade guide. (#5678)
- The kubelet upgrade instructions should be done on every host, not
just worker nodes.
- We should just upgrade all packages, instead of calling out kubelet
specifically. This will also upgrade kubectl, kubeadm, and
kubernetes-cni, if installed.
- Draining nodes should also ignore daemonsets, and master errors can be
ignored.
- Make sure that the new kubeadm download is chmoded correctly.
- Add a step to run `kubeadm version` to verify after downloading.
- Manually approve new kubelet CSRs if rotation is enabled (known issue).
* Release 1.8 (#5680)
* Fix versions for 1.8 API ref docs
* Updates for 1.8 kubectl reference docs
* Kubeadm /docs/admin/kubeadm.md cleanup, editing. (#5681)
* Update docs/admin/kubeadm.md (mostly 1.8 related).
This is Fabrizio's work, which I'm committing along with my edits (in a commit on top of this).
* A few of my own edits to clarify and clean up some Markdown.
2017-09-29 04:46:51 +00:00
|
|
|
`.spec.template.updateStrategy.type` to `OnDelete`.
|
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
Patch the `web` StatefulSet to use the `OnDelete` update strategy:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"OnDelete"}}}'
|
|
|
|
```
|
|
|
|
```
|
|
|
|
statefulset.apps/web patched
|
|
|
|
```
|
|
|
|
|
|
|
|
When you select this update strategy, the StatefulSet controller does not
|
|
|
|
automatically update Pods when a modification is made to the StatefulSet's
|
|
|
|
`.spec.template` field. You need to manage the rollout yourself - either
|
|
|
|
manually, or using separate automation.
|
Release 1.8 (#5659)
* GC now supports non-core resources
* Add two examples about how to analysis audits of kube-apiserver (#4264)
* Deprecate system:nodes binding
* [1.8] StatefulSet `initialized` annotation is now ignored.
* inits the kubeadm upgrade docs
addresses kubernetes/kubernetes.github.io/issues/4689
* adds kubeadm upgrade cmd to ToC
addresses kubernetes/kubernetes.github.io/issues/4689
* add workload placement docs
* ScaleIO - document udpate for 1.8
* Add documentation on storageClass.mountOptions and PV.mountOptions (#5254)
* Add documentation on storageClass.mountOptions and PV.mountOptions
* convert notes into callouts
* Add docs for CustomResource validation
add info about supported fields
* advanced audit beta features (#5300)
* Update job workload doc with backoff failure policy (#5319)
Add to the Jobs documentation how to use the new backoffLimit field that
limit the number of Pod failure before considering the Job as failed.
* Documented additional AWS Service annotations (#4864)
* Add device plugin doc under concepts/cluster-administration. (#5261)
* Add device plugin doc under concepts/cluster-administration.
* Update device-plugins.md
* Update device-plugins.md
Add meta description. Fix typo. Change bare metal deployment to manual deployment.
* Update device-plugins.md
Fix typo again.
* Update page.version. (#5341)
* Add documentation on storageClass.reclaimPolicy (#5171)
* [Advanced audit] use new herf for audit-api (#5349)
This tag contains all the changes in v1beta1 version. Update it now.
* Added documentation around creating the InitializerConfiguration for the persistent volume label controller in the cloud-controller-manager (#5255)
* Documentation for kubectl plugins (#5294)
* Documentation for kubectl plugins
* Update kubectl-plugins.md
* Update kubectl-plugins.md
* Updated CPU manager docs to match implementation. (#5332)
* Noted limitation of alpha static cpumanager.
* Updated CPU manager docs to match implementation.
- Removed references to CPU pressure node condition and evictions.
- Added note about new --cpu-manager-reconcile-period flag.
- Added note about node allocatable requirements for static policy.
- Noted limitation of alpha static cpumanager.
* Move cpu-manager task link to rsc mgmt section.
* init containers annotation removed in 1.8 (#5390)
* Add documentation for TaintNodesByCondition (#5352)
* Add documentation for TaintNodesByCondition
* Update nodes.md
* Update taint-and-toleration.md
* Update daemonset.md
* Update nodes.md
* Update taint-and-toleration.md
* Update daemonset.md
* Fix deployments (#5421)
* Document extended resources and OIR deprecation. (#5399)
* Document extended resources and OIR deprecation.
* Updated extended resources doc per reviews.
* reverts extra spacing in _data/tasks.yml
* addresses `kubeadm upgrade` review comments
Feedback from @chenopis, @luxas, and @steveperry-53 addressed with this commit
* HugePages documentation (#5419)
* Update cpu-management-policies.md (#5407)
Fixed the bad link.
Modified "cpu" to "CPU".
Added more 'yaml' as supplement.
* Update RBAC docs for v1 (#5445)
* Add user docs for pod priority and preemption (#5328)
* Add user docs for pod priority and preemption
* Update pod-priority-preemption.md
* More updates
* Update docs/admin/kubeadm.md for 1.8 (#5440)
- Made a couple of minor wording changes (not strictly 1.8 related).
- Did some reformatting (not strictly 1.8 related).
- Updated references to the default token TTL (was infinite, now 24 hours).
- Documented the new `--discovery-token-ca-cert-hash` and `--discovery-token-unsafe-skip-ca-verification` flags for `kubeadm join`.
- Added references to the new `--discovery-token-ca-cert-hash` flag in all the default examples.
- Added a new _Security model_ section that describes the security tradeoffs of the various discovery modes.
- Documented the new `--groups` flag for `kubeadm token create`.
- Added a note of caution under _Automating kubeadm_ that references the _Security model_ section.
- Updated the component version table to drop 1.6 and add 1.8.
- Update `_data/reference.yml` to try to get the sidebar fixed up and more consistent with `kubefed`.
* Update StatefulSet Basics for 1.8 release (#5398)
* addresses `kubeadm upgrade` review comments
2nd iteration review comments by @luxas
* adds kubelet upgrade section to kubeadm upgrade
* Fix a bulleted list on docs/admin/kubeadm.md. (#5458)
I updated this doc yesterday and I was absolutely sure I fixed this, but I just saw that this commit got lost somehow.
This was introduced recently in https://github.com/kubernetes/kubernetes.github.io/pull/5440.
* Clarify the API to check for device plugins
* Moving Flexvolume to separate out-of-tree section
* addresses `kubeadm upgrade` review comments
CC: @luxas
* fixes kubeadm upgrade index
* Update Stackdriver Logging documentation (#5495)
* Re-update WordPress and MySQL PV doc to use apps/v1beta2 APIs (#5526)
* Update statefulset concepts doc to use apps/v1beta2 APIs (#5420)
* add document on kubectl's behavior regarding initializers (#5505)
* Update docs/admin/kubeadm.md to cover self-hosting in 1.8. (#5497)
This is a new beta feature in 1.8.
* Update kubectl patch doc to use apps/v1beta2 APIs (#5422)
* [1.8] Update "Run Applications" tasks to apps/v1beta2. (#5525)
* Update replicated stateful application task for 1.8.
* Update single instance stateful app task for 1.8.
* Update stateless app task for 1.8.
* Update kubectl patch task for 1.8.
* fix the link of persistent storage (#5515)
* update the admission-controllers.md index.md what-is-kubernetes.md link
* fix the link of persistent storage
* Add quota support for local ephemeral storage (#5493)
* Add quota support for local ephemeral storage
update the doc to this alpha feature
* Update resource-quotas.md
* Updated Deployments concepts doc (#5491)
* Updated Deployments concepts doc
* Addressed comments
* Addressed more comments
* Modify allocatable storage to ephemeral-storage (#5490)
Update the doc to use ephemeral-storage instead of storage
* Revamped concepts doc for ReplicaSet (#5463)
* Revamped concepts doc for ReplicaSet
* Minor changes to call out specific versions for selector defaulting and
immutability
* Addressed doc review comments
* Remove petset documentations (#5395)
* Update docs to use batch/v1beta1 cronjobs (#5475)
* add federation job doc (#5485)
* add federation job doc
* Update job.md
Edits for clarity and consistency
* Update job.md
Fixed a typo
* update DaemonSet concept for 1.8 release (#5397)
* update DaemonSet concept for 1.8 release
* Update daemonset.md
Fix typo. than -> then
* Update bootstrap tokens doc for 1.8. (#5479)
* Update bootstrap tokens doc for 1.8.
This has some changes I missed when I was updating the main kubeadm documention:
- Bootstrap tokens are now beta, not alpha (https://github.com/kubernetes/features/issues/130)
- The apiserver flag to enable the authenticator changedin 1.8 (https://github.com/kubernetes/kubernetes/pull/51198)
- Added `auth-extra-groups` documentaion (https://github.com/kubernetes/kubernetes/pull/50933)
- Updated the _Token Management with `kubeadm`_ section to link to the main kubeadm docs, since it was just duplicated information.
* Update bootstrap-tokens.md
* Updated the Cassandra tutorial to use apps/v1beta2 (#5548)
* add docs for AllowPrivilegeEscalation (#5448)
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
* Add local ephemeral storage alpha feature in managing compute resource (#5522)
* Add local ephemeral storage alpha feature in managing compute resource
Since 1.8, we add the local ephemeral storage alpha feature as one
resource type to manage. Add this feature into the doc.
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Update manage-compute-resources-container.md
* Added documentation for Metrics Server (#5560)
* authorization: improve authorization debugging docs (#5549)
* Document mount propagation (#5544)
* Update /docs/setup/independent/create-cluster-kubeadm.md for 1.8. (#5524)
This introduction needed a couple of small tweaks to cover the `--discovery-token-ca-cert-hash` flag added in https://github.com/kubernetes/kubernetes/pull/49520 and some version bumps.
* Add task doc for alpha dynamic kubelet configuration (#5523)
* Fix input/output of selfsubjectaccess review (#5593)
* Add docs for implementing resize (#5528)
* Add docs for implementing resize
* Update admission-controllers.md
* Added link to PVC section
* minor typo fixes
* Update NetworkPolicy concept guide with egress and CIDR changes (#5529)
* update zookeeper tutorial for 1.8 release
* add doc for hostpath type (#5503)
* Federated Hpa feature doc (#5487)
* Federated Hpa feature doc
* Federated Hpa feature doc review fixes
* Update hpa.md
* Update hpa.md
* update cloud controller manager docs for v1.8
* Update cronjob with defaults information (#5556)
* Kubernetes 1.8 reference docs (#5632)
* Kubernetes 1.8 reference docs
* Kubectl reference docs for 1.8
* Update side bar with 1.8 kubectl and api ref docs links
* remove petset.md
* update on state of HostAlias in 1.8 with hostNetwork Pod support (#5644)
* Fix cron job deletion section (#5655)
* update imported docs (#5656)
* Add documentation for certificate rotation. (#5639)
* Link to using kubeadm page
* fix the command output
fix the command output
* fix typo in api/resources reference: "Worloads"
* Add documentation for certificate rotation.
* Create TOC entry for cloud controller manager. (#5662)
* Updates for new versions of API types
* Followup 5655: fix link to garbage collection (#5666)
* Temporarily redirect resources-reference to api-reference. (#5668)
* Update config for 1.8 release. (#5661)
* Update config for 1.8 release.
* Address reviewer comments.
* Switch references in HPA docs from alpha to beta (#5671)
The HPA docs still referenced the alpha version. This switches them to
talk about v2beta1, which is the appropriate version for Kubernetes 1.8
* Deprecate openstack heat (#5670)
* Fix typo in pod preset conflict example
Move container port definition to the correct line.
* Highlight openstack-heat provider deprecation
The openstack-heat provider for kube-up is being deprecated and will be
removed in a future release.
* Temporarily fix broken links by redirecting. (#5672)
* Fix broken links. (#5675)
* Fix render of code block (#5674)
* Fix broken links. (#5677)
* Add a small note about auto-bootstrapped CSR ClusterRoles (#5660)
* Update kubeadm install doc for v1.8 (#5676)
* add draft workloads api content for 1.8 (#5650)
* add draft workloads api content for 1.8
* edits per review, add tables, for 1.8 workloads api doc
* fix typo
* Minor fixes to kubeadm 1.8 upgrade guide. (#5678)
- The kubelet upgrade instructions should be done on every host, not
just worker nodes.
- We should just upgrade all packages, instead of calling out kubelet
specifically. This will also upgrade kubectl, kubeadm, and
kubernetes-cni, if installed.
- Draining nodes should also ignore daemonsets, and master errors can be
ignored.
- Make sure that the new kubeadm download is chmoded correctly.
- Add a step to run `kubeadm version` to verify after downloading.
- Manually approve new kubelet CSRs if rotation is enabled (known issue).
* Release 1.8 (#5680)
* Fix versions for 1.8 API ref docs
* Updates for 1.8 kubectl reference docs
* Kubeadm /docs/admin/kubeadm.md cleanup, editing. (#5681)
* Update docs/admin/kubeadm.md (mostly 1.8 related).
This is Fabrizio's work, which I'm committing along with my edits (in a commit on top of this).
* A few of my own edits to clarify and clean up some Markdown.
2017-09-29 04:46:51 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Deleting StatefulSets
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
StatefulSet supports both _non-cascading_ and _cascading_ deletion. In a
|
|
|
|
non-cascading **delete**, the StatefulSet's Pods are not deleted when the
|
|
|
|
StatefulSet is deleted. In a cascading **delete**, both the StatefulSet and
|
|
|
|
its Pods are deleted.
|
|
|
|
|
|
|
|
Read [Use Cascading Deletion in a Cluster](/docs/tasks/administer-cluster/use-cascading-deletion/)
|
|
|
|
to learn about cascading deletion generally.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Non-cascading delete
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
In one terminal window, watch the Pods in the StatefulSet.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```
|
2023-12-16 14:05:47 +00:00
|
|
|
# End this watch when there are no Pods for the StatefulSet
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Use [`kubectl delete`](/docs/reference/generated/kubectl/kubectl-commands/#delete) to delete the
|
2021-06-11 13:18:12 +00:00
|
|
|
StatefulSet. Make sure to supply the `--cascade=orphan` parameter to the
|
2020-05-24 23:32:37 +00:00
|
|
|
command. This parameter tells Kubernetes to only delete the StatefulSet, and to
|
2023-12-22 11:42:31 +00:00
|
|
|
**not** delete any of its Pods.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2021-06-11 13:18:12 +00:00
|
|
|
kubectl delete statefulset web --cascade=orphan
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps "web" deleted
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the Pods, to examine their status:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get pods -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 6m
|
|
|
|
web-1 1/1 Running 0 7m
|
|
|
|
web-2 1/1 Running 0 5m
|
|
|
|
```
|
|
|
|
|
|
|
|
Even though `web` has been deleted, all of the Pods are still Running and Ready.
|
2020-05-25 00:15:30 +00:00
|
|
|
Delete `web-0`:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete pod web-0
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
pod "web-0" deleted
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Get the StatefulSet's Pods:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl get pods -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-1 1/1 Running 0 10m
|
|
|
|
web-2 1/1 Running 0 7m
|
|
|
|
```
|
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
As the `web` StatefulSet has been deleted, `web-0` has not been relaunched.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
In one terminal, watch the StatefulSet's Pods.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2017-06-27 16:46:39 +00:00
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# Leave this watch running until the next time you start a watch
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
In a second terminal, recreate the StatefulSet. Note that, unless
|
2020-05-25 00:15:30 +00:00
|
|
|
you deleted the `nginx` Service (which you should not have), you will see
|
2016-11-28 22:22:55 +00:00
|
|
|
an error indicating that the Service already exists.
|
|
|
|
|
|
|
|
```shell
|
2023-11-17 19:00:24 +00:00
|
|
|
kubectl apply -f https://k8s.io/examples/application/web/web.yaml
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web created
|
2019-07-24 02:28:14 +00:00
|
|
|
service/nginx unchanged
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Ignore the error. It only indicates that an attempt was made to create the _nginx_
|
|
|
|
headless Service even though that Service already exists.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
Examine the output of the `kubectl get` command running in the first terminal.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-1 1/1 Running 0 16m
|
|
|
|
web-2 1/1 Running 0 2m
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
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 18s
|
|
|
|
web-2 1/1 Terminating 0 3m
|
|
|
|
web-2 0/1 Terminating 0 3m
|
|
|
|
web-2 0/1 Terminating 0 3m
|
|
|
|
web-2 0/1 Terminating 0 3m
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
When the `web` StatefulSet was recreated, it first relaunched `web-0`.
|
2016-11-28 22:22:55 +00:00
|
|
|
Since `web-1` was already Running and Ready, when `web-0` transitioned to
|
2021-02-04 21:41:29 +00:00
|
|
|
Running and Ready, it adopted this Pod. Since you recreated the StatefulSet
|
|
|
|
with `replicas` equal to 2, once `web-0` had been recreated, and once
|
|
|
|
`web-1` had been determined to already be Running and Ready, `web-2` was
|
|
|
|
terminated.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-12-22 11:42:31 +00:00
|
|
|
Now take another look at the contents of the `index.html` file served by the
|
2020-05-25 00:15:30 +00:00
|
|
|
Pods' webservers:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done
|
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
web-0
|
|
|
|
web-1
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Even though you deleted both the StatefulSet and the `web-0` Pod, it still
|
|
|
|
serves the hostname originally entered into its `index.html` file. This is
|
|
|
|
because the StatefulSet never deletes the PersistentVolumes associated with a
|
|
|
|
Pod. When you recreated the StatefulSet and it relaunched `web-0`, its original
|
2016-11-29 18:01:38 +00:00
|
|
|
PersistentVolume was remounted.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Cascading delete
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2016-11-29 18:01:38 +00:00
|
|
|
In one terminal window, watch the Pods in the StatefulSet.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# Leave this running until the next page section
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
In another terminal, delete the StatefulSet again. This time, omit the
|
2021-06-11 13:18:12 +00:00
|
|
|
`--cascade=orphan` parameter.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete statefulset web
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps "web" deleted
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Examine the output of the `kubectl get` command running in the first terminal,
|
2016-11-28 22:22:55 +00:00
|
|
|
and wait for all of the Pods to transition to Terminating.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# This should already be running
|
|
|
|
kubectl get pods --watch -l app=nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Running 0 11m
|
|
|
|
web-1 1/1 Running 0 27m
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
web-0 1/1 Terminating 0 12m
|
|
|
|
web-1 1/1 Terminating 0 29m
|
|
|
|
web-0 0/1 Terminating 0 12m
|
|
|
|
web-0 0/1 Terminating 0 12m
|
|
|
|
web-0 0/1 Terminating 0 12m
|
|
|
|
web-1 0/1 Terminating 0 29m
|
|
|
|
web-1 0/1 Terminating 0 29m
|
|
|
|
web-1 0/1 Terminating 0 29m
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
As you saw in the [Scaling Down](#scaling-down) section, the Pods
|
|
|
|
are terminated one at a time, with respect to the reverse order of their ordinal
|
|
|
|
indices. Before terminating a Pod, the StatefulSet controller waits for
|
2016-11-28 22:22:55 +00:00
|
|
|
the Pod's successor to be completely terminated.
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
{{< note >}}
|
|
|
|
Although a cascading delete removes a StatefulSet together with its Pods,
|
2023-12-22 11:42:31 +00:00
|
|
|
the cascade does **not** delete the headless Service associated with the StatefulSet.
|
2020-05-25 00:15:30 +00:00
|
|
|
You must delete the `nginx` Service manually.
|
|
|
|
{{< /note >}}
|
|
|
|
|
2016-11-28 22:22:55 +00:00
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete service nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
service "nginx" deleted
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
Recreate the StatefulSet and headless Service one more time:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2023-11-17 19:00:24 +00:00
|
|
|
kubectl apply -f https://k8s.io/examples/application/web/web.yaml
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
service/nginx created
|
|
|
|
statefulset.apps/web created
|
2016-11-28 22:22:55 +00:00
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
When all of the StatefulSet's Pods transition to Running and Ready, retrieve
|
2020-05-25 00:15:30 +00:00
|
|
|
the contents of their `index.html` files:
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-25 00:15:30 +00:00
|
|
|
for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done
|
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
web-0
|
|
|
|
web-1
|
|
|
|
```
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Even though you completely deleted the StatefulSet, and all of its Pods, the
|
|
|
|
Pods are recreated with their PersistentVolumes mounted, and `web-0` and
|
2020-05-25 00:15:30 +00:00
|
|
|
`web-1` continue to serve their hostnames.
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2020-08-28 15:09:38 +00:00
|
|
|
Finally, delete the `nginx` Service...
|
2016-11-28 22:22:55 +00:00
|
|
|
|
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete service nginx
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
service "nginx" deleted
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-08-28 15:09:38 +00:00
|
|
|
...and the `web` StatefulSet:
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```shell
|
2016-11-29 19:33:21 +00:00
|
|
|
kubectl delete statefulset web
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2021-02-04 21:41:29 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
statefulset "web" deleted
|
|
|
|
```
|
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
## Pod management policy
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
For some distributed systems, the StatefulSet ordering guarantees are
|
|
|
|
unnecessary and/or undesirable. These systems require only uniqueness and
|
2023-12-22 11:42:31 +00:00
|
|
|
identity.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
You can specify a [Pod management policy](/docs/concepts/workloads/controllers/statefulset/#pod-management-policies)
|
|
|
|
to avoid this strict ordering; either `OrderedReady` (the default), or `Parallel`.
|
|
|
|
|
|
|
|
### OrderedReady Pod management
|
|
|
|
|
|
|
|
`OrderedReady` pod management is the default for StatefulSets. It tells the
|
|
|
|
StatefulSet controller to respect the ordering guarantees demonstrated
|
|
|
|
above.
|
|
|
|
|
|
|
|
Use this when your application requires or expects that changes, such as rolling out a new
|
|
|
|
version of your application, happen in the strict order of the ordinal (pod number) that the StatefulSet provides.
|
|
|
|
In other words, if you have Pods `app-0`, `app-1` and `app-2`, Kubernetes will update `app-0` first and check it.
|
|
|
|
Once the checks are good, Kubernetes updates `app-1` and finally `app-2`.
|
|
|
|
|
|
|
|
If you added two more Pods, Kubernetes would set up `app-3` and wait for that to become healthy before deploying
|
|
|
|
`app-4`.
|
|
|
|
|
|
|
|
Because this is the default setting, you've already practised using it.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-09-20 17:15:33 +00:00
|
|
|
### Parallel Pod management
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
The alternative, `Parallel` pod management, tells the StatefulSet controller to launch or
|
|
|
|
terminate all Pods in parallel, and not to wait for Pods to become `Running`
|
|
|
|
and `Ready` or completely terminated prior to launching or terminating another
|
|
|
|
Pod.
|
|
|
|
|
|
|
|
The `Parallel` pod management option only affects the behavior for scaling operations. Updates are not affected;
|
|
|
|
Kubernetes still rolls out changes in order. For this tutorial, the application is very simple: a webserver that
|
|
|
|
tells you its hostname (because this is a StatefulSet, the hostname for each Pod is different and predictable).
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2023-08-24 10:38:23 +00:00
|
|
|
{{% code_sample file="application/web/web-parallel.yaml" %}}
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
This manifest is identical to the one you downloaded above except that the `.spec.podManagementPolicy`
|
2017-06-27 16:46:39 +00:00
|
|
|
of the `web` StatefulSet is set to `Parallel`.
|
|
|
|
|
|
|
|
In one terminal, watch the Pods in the StatefulSet.
|
|
|
|
|
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# Leave this watch running until the end of the section
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
In another terminal, reconfigure the StatefulSet for `Parallel` Pod management:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-11-17 19:00:24 +00:00
|
|
|
kubectl apply -f https://k8s.io/examples/application/web/web-parallel.yaml
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2023-08-28 22:16:42 +00:00
|
|
|
service/nginx updated
|
|
|
|
statefulset.apps/web updated
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Keep the terminal open where you're running the watch. In another terminal window, scale the
|
2020-05-25 00:15:30 +00:00
|
|
|
StatefulSet:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
2023-08-28 22:16:42 +00:00
|
|
|
kubectl scale statefulset/web --replicas=5
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2018-08-16 23:09:08 +00:00
|
|
|
statefulset.apps/web scaled
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
Examine the output of the terminal where the `kubectl get` command is running. It may look something like
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
web-3 0/1 Pending 0 0s
|
|
|
|
web-3 0/1 Pending 0 0s
|
|
|
|
web-3 0/1 Pending 0 7s
|
|
|
|
web-3 0/1 ContainerCreating 0 7s
|
2023-08-28 22:16:42 +00:00
|
|
|
web-2 0/1 Pending 0 0s
|
|
|
|
web-4 0/1 Pending 0 0s
|
|
|
|
web-2 1/1 Running 0 8s
|
|
|
|
web-4 0/1 ContainerCreating 0 4s
|
2017-06-27 16:46:39 +00:00
|
|
|
web-3 1/1 Running 0 26s
|
2023-08-28 22:16:42 +00:00
|
|
|
web-4 1/1 Running 0 2s
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2023-08-28 22:16:42 +00:00
|
|
|
The StatefulSet launched three new Pods, and it did not wait for
|
|
|
|
the first to become Running and Ready prior to launching the second and third Pods.
|
|
|
|
|
|
|
|
This approach is useful if your workload has a stateful element, or needs Pods to be able to identify each other
|
|
|
|
with predictable naming, and especially if you sometimes need to provide a lot more capacity quickly. If this
|
|
|
|
simple web service for the tutorial suddenly got an extra 1,000,000 requests per minute then you would want to run
|
|
|
|
some more Pods - but you also would not want to wait for each new Pod to launch. Starting the extra Pods in parallel
|
|
|
|
cuts the time between requesting the extra capacity and having it available for use.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
## {{% heading "cleanup" %}}
|
|
|
|
|
|
|
|
You should have two terminals open, ready for you to run `kubectl` commands as
|
|
|
|
part of cleanup.
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl delete sts web
|
2020-05-25 00:15:30 +00:00
|
|
|
# sts is an abbreviation for statefulset
|
2017-06-27 16:46:39 +00:00
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
You can watch `kubectl get` to see those Pods being deleted.
|
2017-06-27 16:46:39 +00:00
|
|
|
```shell
|
2023-12-16 14:05:47 +00:00
|
|
|
# end the watch when you've seen what you need to
|
|
|
|
kubectl get pod -l app=nginx --watch
|
2020-05-25 00:15:30 +00:00
|
|
|
```
|
|
|
|
```
|
2017-06-27 16:46:39 +00:00
|
|
|
web-3 1/1 Terminating 0 9m
|
|
|
|
web-2 1/1 Terminating 0 9m
|
|
|
|
web-3 1/1 Terminating 0 9m
|
|
|
|
web-2 1/1 Terminating 0 9m
|
|
|
|
web-1 1/1 Terminating 0 44m
|
|
|
|
web-0 1/1 Terminating 0 44m
|
|
|
|
web-0 0/1 Terminating 0 44m
|
|
|
|
web-3 0/1 Terminating 0 9m
|
|
|
|
web-2 0/1 Terminating 0 9m
|
|
|
|
web-1 0/1 Terminating 0 44m
|
|
|
|
web-0 0/1 Terminating 0 44m
|
|
|
|
web-2 0/1 Terminating 0 9m
|
|
|
|
web-2 0/1 Terminating 0 9m
|
|
|
|
web-2 0/1 Terminating 0 9m
|
|
|
|
web-1 0/1 Terminating 0 44m
|
|
|
|
web-1 0/1 Terminating 0 44m
|
|
|
|
web-1 0/1 Terminating 0 44m
|
|
|
|
web-0 0/1 Terminating 0 44m
|
|
|
|
web-0 0/1 Terminating 0 44m
|
|
|
|
web-0 0/1 Terminating 0 44m
|
|
|
|
web-3 0/1 Terminating 0 9m
|
|
|
|
web-3 0/1 Terminating 0 9m
|
|
|
|
web-3 0/1 Terminating 0 9m
|
|
|
|
```
|
|
|
|
|
2020-05-25 00:15:30 +00:00
|
|
|
During deletion, a StatefulSet removes all Pods concurrently; it does not wait for
|
2017-06-27 16:46:39 +00:00
|
|
|
a Pod's ordinal successor to terminate prior to deleting that Pod.
|
|
|
|
|
2020-05-24 23:32:37 +00:00
|
|
|
Close the terminal where the `kubectl get` command is running and delete the `nginx`
|
2020-05-25 00:15:30 +00:00
|
|
|
Service:
|
2017-06-27 16:46:39 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl delete svc nginx
|
|
|
|
```
|
2016-11-28 22:22:55 +00:00
|
|
|
|
2022-07-14 08:10:42 +00:00
|
|
|
Delete the persistent storage media for the PersistentVolumes used in this tutorial.
|
2020-05-30 19:10:23 +00:00
|
|
|
|
2022-07-14 08:10:42 +00:00
|
|
|
```shell
|
|
|
|
kubectl get pvc
|
|
|
|
```
|
|
|
|
```
|
|
|
|
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
|
|
|
|
www-web-0 Bound pvc-2bf00408-d366-4a12-bad0-1869c65d0bee 1Gi RWO standard 25m
|
|
|
|
www-web-1 Bound pvc-ba3bfe9c-413e-4b95-a2c0-3ea8a54dbab4 1Gi RWO standard 24m
|
|
|
|
www-web-2 Bound pvc-cba6cfa6-3a47-486b-a138-db5930207eaf 1Gi RWO standard 15m
|
|
|
|
www-web-3 Bound pvc-0c04d7f0-787a-4977-8da3-d9d3a6d8d752 1Gi RWO standard 15m
|
|
|
|
www-web-4 Bound pvc-b2c73489-e70b-4a4e-9ec1-9eab439aa43e 1Gi RWO standard 14m
|
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl get pv
|
|
|
|
```
|
|
|
|
```
|
|
|
|
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
|
|
|
|
pvc-0c04d7f0-787a-4977-8da3-d9d3a6d8d752 1Gi RWO Delete Bound default/www-web-3 standard 15m
|
|
|
|
pvc-2bf00408-d366-4a12-bad0-1869c65d0bee 1Gi RWO Delete Bound default/www-web-0 standard 25m
|
|
|
|
pvc-b2c73489-e70b-4a4e-9ec1-9eab439aa43e 1Gi RWO Delete Bound default/www-web-4 standard 14m
|
|
|
|
pvc-ba3bfe9c-413e-4b95-a2c0-3ea8a54dbab4 1Gi RWO Delete Bound default/www-web-1 standard 24m
|
|
|
|
pvc-cba6cfa6-3a47-486b-a138-db5930207eaf 1Gi RWO Delete Bound default/www-web-2 standard 15m
|
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl delete pvc www-web-0 www-web-1 www-web-2 www-web-3 www-web-4
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
persistentvolumeclaim "www-web-0" deleted
|
|
|
|
persistentvolumeclaim "www-web-1" deleted
|
|
|
|
persistentvolumeclaim "www-web-2" deleted
|
|
|
|
persistentvolumeclaim "www-web-3" deleted
|
|
|
|
persistentvolumeclaim "www-web-4" deleted
|
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl get pvc
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
No resources found in default namespace.
|
|
|
|
```
|
2020-05-25 00:15:30 +00:00
|
|
|
{{< note >}}
|
|
|
|
You also need to delete the persistent storage media for the PersistentVolumes
|
|
|
|
used in this tutorial.
|
|
|
|
Follow the necessary steps, based on your environment, storage configuration,
|
|
|
|
and provisioning method, to ensure that all storage is reclaimed.
|
2024-04-12 00:29:30 +00:00
|
|
|
{{< /note >}}
|