Slide 1

Slide 1 text

STATEFUL APPLICATIONS MIT KUBERNETES BED-CON 2017 Nicolas Byl, codecentric AG 1

Slide 2

Slide 2 text

2

Slide 3

Slide 3 text

PERSISTENT APPLICATION STATE 3 . 1

Slide 4

Slide 4 text

GOALS Scalable Highly Available Fault Tolerance 3 . 2

Slide 5

Slide 5 text

EXAMPLE ARCHITECTURE 3 . 3

Slide 6

Slide 6 text

CANDIDATES MySQL PostgreSQL Cassandra MongoDB Kafka … 3 . 4

Slide 7

Slide 7 text

KUBERNETES 4 . 1

Slide 8

Slide 8 text

DESIGN PHILOSOPHY portable: public, private, hybrid, multi-cloud extensible: modular, pluggable, hookable, composable self-healing: auto-placement, auto-restart, auto-replication, auto-scaling 4 . 2

Slide 9

Slide 9 text

PODS 4 . 3

Slide 10

Slide 10 text

SERVICES 4 . 4

Slide 11

Slide 11 text

PERSISTENT VOLUMES 5 . 1

Slide 12

Slide 12 text

5 . 2

Slide 13

Slide 13 text

GCEPersistentDisk CephFS AWSElasticBlockStore Cinder (OpenStack block storage) AzureFile Glusterfs AzureDisk VsphereVolume FC (Fibre Channel) Quobyte Volumes FlexVolume HostPath Flocker VMware Photon

Slide 14

Slide 14 text

NFS vPortworx Volumes iSCSI ScaleIO Volumes RBD (Ceph Block Device) StorageOS 5 . 3

Slide 15

Slide 15 text

ACCESS MODES ReadWriteOnce – the volume can be mounted as read-write by a single node ReadOnlyMany – the volume can be mounted read-only by many nodes ReadWriteMany – the volume can be mounted as read-write by many nodes 5 . 4

Slide 16

Slide 16 text

USAGE Provision Disk Create Persistent Volume Create Persistent Volume Claim Mount Claim in Pod 5 . 5

Slide 17

Slide 17 text

PERSISTENT VOLUME apiVersion: v1 kind: PersistentVolume metadata: name: pv0003 spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle nfs: path: /tmp server: 172.17.0.2 5 . 6

Slide 18

Slide 18 text

PERSISTENT VOLUME CLAIM kind: PersistentVolumeClaim apiVersion: v1 metadata: name: myclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 8Gi 5 . 7

Slide 19

Slide 19 text

MOUNTING A PVC kind: Pod apiVersion: v1 metadata: name: mypod spec: containers: - name: mydatabase image: mysql:5.7 volumeMounts: - mountPath: "/var/lib/mysql" name: mypd volumes: - name: mypd persistentVolumeClaim: claimName: myclaim 5 . 8

Slide 20

Slide 20 text

COMMON PITFALLS The abstraction is leaky. Local storage vs. SAN storage vs. Network Filesystems 5 . 9

Slide 21

Slide 21 text

AUTO-PROVISIONING 6 . 1

Slide 22

Slide 22 text

AUTO-PROVISIONING Manual creation of Persistent Volumes is error-prone. Does not scale well. 6 . 2

Slide 23

Slide 23 text

STORAGECLASS kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: standard provisioner: kubernetes.io/aws-ebs parameters: type: gp2 6 . 3

Slide 24

Slide 24 text

USING A STORAGECLASS kind: PersistentVolumeClaim apiVersion: v1 metadata: name: myclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 8Gi storageClassName: standard 6 . 4

Slide 25

Slide 25 text

SUPPORTED PROVISIONERS default volume plugins (in-tree provisioners) out-of-tree provisioners community provisioners: write your own: https://github.com/kubernetes- incubator/external-storage https://github.com/kubernetes- incubator/external- storage/tree/master/docs/demo/hostpath-provisioner 6 . 5

Slide 26

Slide 26 text

SCALING 7 . 1

Slide 27

Slide 27 text

ARCHITECTURE REVISITED 7 . 2

Slide 28

Slide 28 text

SHARING PVCS Need different paths per Pod. Share needs to be available on every host. Corruption of file system affects all database nodes. Sharing a Persistent Volume Claim is not a good idea. 7 . 3

Slide 29

Slide 29 text

STATEFUL SETS 8 . 1

Slide 30

Slide 30 text

STATEFULSETS Pod template mechanism Hostnames are atomically increased: pod-0 pod-1 … Volume Claims can be provisioned on-the-fly 8 . 2

Slide 31

Slide 31 text

STATEFULSET EXAMPLE apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: web spec: serviceName: "nginx" replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: gcr.io/google_containers/nginx-slim:0.8 ports: - containerPort: 80 name: web volumeMounts: 8 . 3

Slide 32

Slide 32 text

ARCHITECTURE STATEFULSETS 8 . 4

Slide 33

Slide 33 text

WRAP UP 9 . 1

Slide 34

Slide 34 text

LINKS Persistent Volumes: Tutorial StatefulSet: Demos: https://kubernetes.io/docs/concepts/storage/persistent- volumes https://kubernetes.io/docs/tutorials/stateful-application/basic- stateful-set/ https://goo.gl/NCnzq8 9 . 2

Slide 35

Slide 35 text

THE END Copyright 2017 @NicolasByl 9 . 3