Cloud native applications are commonly thought as stateless, horizontally scalable workloads that you can scale-up and down on-demand. Kubernetes, as the commodity cloud native orchestrator, was originally designed for such workloads. A lot has evolved since Kubernetes’ inception, and nowadays many of the stateful applications are migrating to Kubernetes. While not everything is perfect, more and more features are added to support complex stateful use-cases. In this session Arthur will cover the following topics:
- Breakdown of a stateful application
- Planning a stateful application on Kubernetes
- The state of Kubernetes StatefulSets, Persistent Volumes, DNS, Networking, operators and High Availability
- A practical use-case and DEMO of a stateful application with Kubernetes
17. Dynamic Storage Provisioning
PersistentVolume(pv)
Persistent Volume (PV) represents provisioned storage in the cluster
Can be backed by NFS, iSCSI, other block, etc
PV’s lifecycle is independent of the container/pod that uses it
PVs are not deleted when the Pods
27. StatefulSets
1. Stable, unique DNS network identifiers.
2. Stable, persistent storage.
3. Ordered, graceful deployment and scaling.
4. Ordered, automated rolling updates.
28. GA in Kubernetes 1.9 (Dec 16, 2017)
Controller that manages deployment and scaling of Pods
StatefulSet maintains a sticky identity for each of their Pods
Provides guarantees about ordering and uniqueness
StatefulSets
29. StatefulSet
Ordinal Index
$(statefulset name)-$(ordinal)
[arthurberezin@roadster demo]$ kubectl get StatefulSets
NAME DESIRED CURRENT AGE
web 2 2 2m
[arthurberezin@roadster demo]$ kubectl get pods
NAME READY STATUS RESTARTS
AGE
web-0 1/1 Running 0
2m
web-1 1/1 Running 0
2m
Stable Network ID
web-{0..N-1}.nginx.default.svc.cluster.local
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
serviceName: "nginx"
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
30. StatefulSet
VolumeClaimTemplates
One PersistentVolume for each pod
Re-mounted on Pod re-schedule
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
resources:
requests:
storage: 1Gi