Five Great Ways to Lose Data on Kubernetes - KubeCon EU 2020
1. Five Great Ways to Lose
Data on Kubernetes
(And How to Avoid Them)
Robert Hodges - KubeCon Europe 2020
1
2. Presenter and Company Bio
www.altinity.com
Enterprise provider for ClickHouse, a
popular, open source data warehouse.
Implementors of ClickHouse
Kubernetes operator.
Robert Hodges - Altinity CEO
30+ years on DBMS plus
virtualization and security. Using
Kubernetes since 2018.
2
4. What do we mean by “data”?
Rep SKU Date City Customer Units Price ...
25 #556 25 Nov SFO Wells Fargo 378 $25.00
36 #556 25 Nov SEA Boeing 259 $25.50
55 #558 28 Nov BOS Au Bon Pain 100 $29.33
... ... ... ... ... ... ...
Which products
have the best
gross margins
over time?
Do some SKUs
sell better on
different days
of the week?
Which kinds of
companies are
most likely to
buy SKU 556? 4
5. And what do we mean by “lose”?
The data loss “arrow of evil”
Temporarily
unavailable
All of it gone,
forever
Can’t process
transactions
Unable to see
market
conditions
Business stops
functioning
5
10. Simplest K8s path to replicas: use an operator
Kubernetes
Operator
Single specification
Best practice
deployment
Custom
Resource
Definition
Kubernetes API
Native
Controller
Native
Controller
Native
Controllers
Etcd
Pod Service
StatefulSet
10
11. Complex systems made simple[r]
apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"
metadata:
name: "ch01"
spec:
configuration:
clusters:
- name: replicated
layout:
shardsCount: 2
replicasCount: 2
zookeeper:
nodes:
- host: zookeeper.zk
Name to identify resource
Definition of cluster
Name of service we depend on
11
16. Node affinity + failure domain covers AZ failure
apiVersion: v1
kind: Pod
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: failure-domain.beta.kubernetes.io/zone
operator: In
values:
- us-west-2a
16
17. Protect replicas using distance
CH PodCH Pod
Zookeeper
Pod
CH PodCH Pod
Zookeeper
Pod
us-west-2a
us-west-2b
CH PodCH Pod
Zookeeper
Pod
us-west-2c
DBMS
Copy
DBMS
CopyBackup
Host
Object
Storage
17
20. Where are my pods running?
kubectl get pod
-o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nod
eName -n zk
NAME STATUS NODE
zookeeper-0 Running ip-172-20-49-116.us-west-2.compute.internal
zookeeper-1 Running ip-172-20-71-114.us-west-2.compute.internal
zookeeper-2 Running ip-172-20-49-116.us-west-2.compute.internal
20
21. Which hosts are in which AZs?
kubectl get node
-o=custom-columns=NODE:.metadata.name,ZONE:.metadata.labels.'failure-doma
in.beta.kubernetes.io/zone'
NODE ZONE
ip-172-20-47-4.us-west-2.compute.internal us-west-2a
ip-172-20-49-116.us-west-2.compute.internal us-west-2a
ip-172-20-52-196.us-west-2.compute.internal us-west-2a
ip-172-20-70-184.us-west-2.compute.internal us-west-2b
ip-172-20-71-114.us-west-2.compute.internal us-west-2b
21
25. Kubernetes Node
Ephemeral storage is a feature, not a bug!
“bad”
pod
Kubernetes Node
“good”
pod
Network
Storage
Application Application
25
26. Things to look for in database storage
kubectl get pvc -o=custom-columns=NAME:.metadata.name
,SIZE:.spec.resources.request.storage,
CLASS:.spec.storageClassName,VOLUME:.spec.volumeName
...
NAME SIZE CLASS VOLUME
storage...0-0-0 10Gi kops-ssd-1-17 pvc-8f86...7a8
kubectl get storageclass/kops-ssd-1-17
...
NAME PROVISIONER RECLAIMPOLICY..
kops-ssd-1-17 (default) kubernetes.io/aws-ebs Delete
26
27. PVs are not enough if you don’t use them!
Kubernetes Node
EBS
Storage
Application
“zookeeper” pod
/data /datalog /var/lib/zk/data
Ephemeral Storage
27
28. Testing to the point of abuse is the solution
Check Kubernetes resource definitions
Inspect file system mounts
Kill pods
Kill nodes
Kill and restart all pods in replicated databases
Delete volumes
Test with large amounts of data
28
36. How to avoid losing data on Kubernetes
Replicas!
Indulg i
Paranoi !
Distance!
Testing!
Affinity
Rules!
Reclaim
Policies!
Use operators if available
36