Slide 1

Slide 1 text

Infrastructure testing using Kubernetes @rantav

Slide 2

Slide 2 text

Infrastructure testing using Kubernetes OR: Testing Kafka replication over the Atlantic using Golang, Kubernetes and friends

Slide 3

Slide 3 text

THE GOAL Test Kafka replication across the Atlantic

Slide 4

Slide 4 text

Hello! I am Ran Tavory I work on multi-region You can find me @rantav (slack/twitter/email) 4

Slide 5

Slide 5 text

The Goal: Test Kafka Replication ⊙ Replicate 30MB - 300MB of traffic per second ⊙ Validate correctness ⊙ Measure latency ⊙ Run test cases ○ Broker crash, cluster resize, packet loss... 5

Slide 6

Slide 6 text

HOW ? High level design 6

Slide 7

Slide 7 text

Kafka Replication From https://github.com/AppsFlyer/kafka-mirror-tester 7

Slide 8

Slide 8 text

With a home-grown producer and consumer 8

Slide 9

Slide 9 text

WHAT DO WE WANT? 9 DOCUMENTATION

Slide 10

Slide 10 text

WHAT DO WE WANT? 10 REPRODUCIBILITY

Slide 11

Slide 11 text

WHAT DO WE WANT? 11 MONITORING

Slide 12

Slide 12 text

KUBERNETES 12

Slide 13

Slide 13 text

You keep saying this word Kubernetes What does it mean? 13

Slide 14

Slide 14 text

A brief introduction to Kubernetes 14

Slide 15

Slide 15 text

CLUSTER MANAGER Kubernetes is a 15

Slide 16

Slide 16 text

NODES The host running a kubelet and a set of Pods 16 It manages

Slide 17

Slide 17 text

PODS Pods consist of 1 or more containers 17 Nodes contain

Slide 18

Slide 18 text

DEPLOYMENTS A set of stateless pods 18 Pods run

Slide 19

Slide 19 text

STATEFUL SET A set of stateful pods 19 Pods also run

Slide 20

Slide 20 text

KUBECTL The k8s CLI 20 You control k8s using

Slide 21

Slide 21 text

Slide 22

Slide 22 text

$ make k8s-all 22

Slide 23

Slide 23 text

What does that do? ⊙ Provision VMs in AWS ⊙ Setup VPCs, Subnets, Routing Tables ⊙ Create Security Groups ⊙ Setup Load Balancers ⊙ Install Kubernetes (etcd, masters, nodes) ⊙ Setup Monitoring (Prometheus & Grafana and install dashboard) ⊙ Install Weave Scope ⊙ Install Kafkas (and test them) ⊙ Install uReplicator (and test it) ⊙ Install test programs ⊙ And more… (ASGs, DHCP etc) 23

Slide 24

Slide 24 text

$ kops create cluster \ --zones us-east-1a,us-east-1b,us-east-1c \ --node-count 40 \ --node-size i3.large \ --master-size m4.large \ --master-zones us-east-1a \ --networking calico \ --cloud aws 24

Slide 25

Slide 25 text

What are we building? us-east-1 25 eu-west-1

Slide 26

Slide 26 text

What are we building? us-east-1 40 nodes k8s cluster 26 eu-west-1 48 nodes k8s cluster

Slide 27

Slide 27 text

What are we building? us-east-1 40 nodes k8s cluster 30 brokers kafka cluster 27 eu-west-1 48 nodes k8s cluster 30 brokers kafka cluster

Slide 28

Slide 28 text

What are we building? us-east-1 40 nodes k8s cluster 30 brokers kafka cluster 28 eu-west-1 48 nodes k8s cluster 30 brokers kafka cluster 8 workers uReplicator

Slide 29

Slide 29 text

What are we building? us-east-1 40 nodes k8s cluster 30 brokers kafka cluster 10 producers 29 eu-west-1 48 nodes k8s cluster 30 brokers kafka cluster 8 workers uReplicator 4 consumers

Slide 30

Slide 30 text

30 End Result

Slide 31

Slide 31 text

31 Grafana Dashboard

Slide 32

Slide 32 text

32 Prometheus

Slide 33

Slide 33 text

33 Weave Scope

Slide 34

Slide 34 text

34 Weave Scope

Slide 35

Slide 35 text

35 Weave Scope

Slide 36

Slide 36 text

36 kubectl example

Slide 37

Slide 37 text

TEST IT. Let’s put all this to test now 37

Slide 38

Slide 38 text

$ kubectl \ --context us-east-1.k8s.local \ -n kafka-source \ delete pod kafka-source-2 38 KILL A BROKER

Slide 39

Slide 39 text

39 KILL A BROKER

Slide 40

Slide 40 text

$ kubectl \ --context us-east-1.k8s.local \ -n kafka-source \ scale \ statefulset kafka-source \ --replicas 29 40 RESIZE KAFKA CLUSTER

Slide 41

Slide 41 text

41 RESIZE KAFKA CLUSTER

Slide 42

Slide 42 text

$ kubectl \ --context eu-west-1.k8s.local \ -n ureplicator \ scale deployment \ ureplicator-worker \ --replicas 9 42 ADD uREPLICATOR WORKER

Slide 43

Slide 43 text

43 ADD uREPLICATOR WORKER

Slide 44

Slide 44 text

$ make k8s-redeploy-tests 44 ADD NEW TOPIC

Slide 45

Slide 45 text

45 ADD NEW TOPIC

Slide 46

Slide 46 text

$ make k8s-kafka-shell-source $ bin/kafka-topics.sh --zookeeper zookeeper:2181 --alter --topic topic5 --partitions 300 46 ADD PARTITIONS

Slide 47

Slide 47 text

$ kubectl --context eu-west-1.k8s.local \ -n ureplicator port-forward \ ureplicator-controller-76ff85b889-l9mzl 9000 $ curl -X DELETE http://localhost:9000/topics/topic5 $ curl -X POST -d \ '{"topic":"topic5", "numPartitions":"300"}' \ http://localhost:9000/topics 47 ADD PARTITIONS (cont)

Slide 48

Slide 48 text

48 PACKET LOSS

Slide 49

Slide 49 text

49 PACKET LOSS

Slide 50

Slide 50 text

CODE DEEP DIVE Kubernetes, head first (just a few bites) 50

Slide 51

Slide 51 text

51 Kafka kind: StatefulSet replicas: 30

Slide 52

Slide 52 text

Kafka Main container 52 image ports resources probes

Slide 53

Slide 53 text

53 Kafka config

Slide 54

Slide 54 text

54 Metrics sidecar container

Slide 55

Slide 55 text

55 Kafka anti- affinity

Slide 56

Slide 56 text

56 uReplicator deployment

Slide 57

Slide 57 text

57 Producer deployment

Slide 58

Slide 58 text

58 Consumer deployment

Slide 59

Slide 59 text

59 Service monitoring

Slide 60

Slide 60 text

CODE DEEP DIVE Golang Producer/Consumer (just a few bites) 60

Slide 61

Slide 61 text

61 Producer Main loop

Slide 62

Slide 62 text

62 Producer channels p.ProduceChannel() <- m

Slide 63

Slide 63 text

63 Consumer Main loop Loop until: signaled || done. Process event Type switch

Slide 64

Slide 64 text

64 Consumer Process message

Slide 65

Slide 65 text

“ Question: How can multiple consumers validate message arrival order? 65

Slide 66

Slide 66 text

66 Producer Sequence numbers messageKey = seq % partitions perKeySeq = seq / partitions

Slide 67

Slide 67 text

$ make k8s-delete-all 67

Slide 68

Slide 68 text

68

Slide 69

Slide 69 text

Thanks! Any questions? You can find me at @rantav & [email protected] 69 This presentation: https://speakerdeck.com/rantav/infrastructure-testing-using-kubernetes