You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
a5b4383297
* fix: fix internal service filename in 08-service section * fix: typo * fix: fix markdownlint in CI * fix: typo * fix: typo * fix: `environment variables`, not `environmental` * fix: typo & missing punctuation * fix: `much` not `many` * fix: `lets` not `let's` * fix: typo * fix: typo * fix: phrasing * fix: typo * fix: typo * fix: mysql operator manifest api version got this error while trying to run it as is: error: unable to recognize "20-operators/01-mysql-operator.yml": no matches for kind "Deployment" in version "apps/v1beta1" * fix: spelling |
4 years ago | |
---|---|---|
.. | ||
01-statefulset.yml | 5 years ago | |
README.md | 4 years ago |
README.md
Stateful Sets
Introduction
Like a Deployment
, a StatefulSet
manages Pods that are based on an identical container spec. Unlike a Deployment
, a StatefulSet
maintains a sticky identity for each the pods. These are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.
StatefulSets
are valuable for applications that require one or more of the following.
- Stable, unique network identifiers, ex: distributed system, like ElasticSearch
- Stable, persistent storage, ex: MySQL
- Ordered, graceful deployment and scaling
- Ordered, automated rolling updates, ex: MySQL Master+Slave
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
As you can see the manifest is very close to the one of a deployment. Apply the manifest 01-statefulset.yml.
Look at the pods generated, see how they are generated. Connect to one of the pods:
kubectl exec -ti web-0 /bin/bash
Write a file in the volume www
. Terminate the same pod. See what happens. Reconnect to the pod, look at volume www
. What can you see?
Clean up
kubectl delete statefulset,deployment,service,pod --all