Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kafka on Kubernetes: Keeping It Simple

Nikki Thean
October 01, 2019

Kafka on Kubernetes: Keeping It Simple

I gave a presentation at Kafka Summit San Francisco 2019 that attempts to convince viewers that it is possible to run a stable Kafka cluster on Kubernetes without a complicated setup.

Bonus: I illustrated the slides by hand, and hid the Kafka logo in many of the pictures!

The talk description is below:

If you’ve ever thought that running Kafka on Kubernetes was a terrible idea, welcome to the club: that’s what we thought as well. When we migrated Etsy’s Kafka deployment from bare metal to GCP, we made a surprising discovery: running Kafka on Kubernetes was the best option for us — and it wasn’t half as complicated as we thought it had to be.

I’ll use the story of our cloud migration journey to frame a discussion of how a “simple” Kafka-on-k8s setup can work. You’ll walk away with an example of how to set up a stable production system that uses vanilla Kubernetes workloads, as well as some technical tips and tricks — and pitfalls to avoid — for your own cloud migration or first Kafka-on-k8s deployment.

Nikki Thean

October 01, 2019
Tweet

Other Decks in Technology

Transcript

  1. ONE YEAR LATER 1. Production Kafka cluster on Kubernetes. 2.

    Suggesting this idea to other people.
  2. ONE YEAR LATER 1. Production Kafka cluster on Kubernetes. 2.

    Suggesting this idea to other people.
  3. RUNNING KAFKA ON KUBERNETES DOESN'T HAVE TO BE COMPLICATED. *

    "Complicated" = custom resource definitions, plugins, operators, etc.
  4. WHAT YOU’LL GET OUT OF THIS ➤ Example of real-life

    production setup ➤ Technical tips and tricks
  5. WHAT YOU’LL GET OUT OF THIS ➤ Example of real-life

    production setup ➤ Technical tips and tricks ➤ Advice for migrating production systems
  6. SYSTEMS MENTIONED ➤ Kafka ➤ Kubernetes ➤ Chef ➤ Terraform

    ➤ Helm ➤ Prometheus ➤ Google Cloud Platform
  7. SYSTEMS MENTIONED ➤ Kafka ➤ Kubernetes ➤ Chef ➤ Terraform

    ➤ Helm ➤ Prometheus ➤ Google Cloud Platform
  8. SYSTEMS MENTIONED ➤ Kafka ➤ Kubernetes ➤ Chef ➤ Terraform

    ➤ Helm ➤ Prometheus ➤ Google Cloud Platform
  9. WHAT WE CONSIDERED ➤ VMs + Chef ➤ Mutable infrastructure

    ➤ VMs + Machine/Docker Images ➤ Same amount of toil, new cloud infra problems
  10. WHAT WE CONSIDERED ➤ VMs + Chef ➤ Mutable infrastructure

    ➤ VMs + Machine/Docker Images ➤ Same amount of toil, new cloud infra problems ➤ Managed Instance Groups
  11. WHAT WE CONSIDERED ➤ VMs + Chef ➤ Mutable infrastructure

    ➤ VMs + Machine/Docker Images ➤ Same amount of toil, new cloud infra problems ➤ Managed Instance Groups ➤ Not good for stateful workloads
  12. WHAT WE CONSIDERED ➤ VMs + Chef ➤ Mutable infrastructure

    ➤ VMs + Machine/Docker Images ➤ Same amount of toil, new cloud infra problems ➤ Managed Instance Groups ➤ Not good for stateful workloads ➤ …Kubernetes?!
  13. WHAT WE CONSIDERED ➤ VMs + Chef ➤ Mutable infrastructure

    ➤ VMs + Machine/Docker Images ➤ Same amount of toil, new cloud infra problems ➤ Managed Instance Groups ➤ Not good for stateful workloads ➤ …Kubernetes?!
  14. RESOURCE MANAGEMENT ➤ Examples of separation: ➤ zones ➤ node

    type - varying workloads, e.g. high CPU requirement
  15. RESOURCE MANAGEMENT ➤ Examples of separation: ➤ zones ➤ node

    pools - varying workloads, e.g. high CPU requirement ➤ Workload allocation controlled by: ➤ nodeSelectors ➤ pool: highmem ➤ failure-domain.beta.kubernetes.io/zone: us-central1-a
  16. RESOURCE MANAGEMENT ➤ Examples of separation: ➤ zones ➤ node

    pools - varying workloads, e.g. high CPU requirement ➤ Workload allocation controlled by: ➤ nodeSelectors ➤ pool: highmem ➤ failure-domain.beta.kubernetes.io/zone: us-central1-a ➤ taints + tolerations ➤ - key: pool
 operator: Equal
 value: highmem
 effect: NoSchedule
  17. SERVICE DISCOVERY ➤ Within the cluster: ClusterIP Service ➤ e.g.

    Kafka broker to Kafka broker, Kafka Connect worker to Kafka broker
  18. SERVICE DISCOVERY ➤ Within the cluster: ClusterIP Service ➤ e.g.

    Kafka broker to Kafka broker, Kafka Connect worker to Kafka broker ➤ External services to Kafka: ➤ Bootstrapping: Cloud DNS to LoadBalancer
  19. SERVICE DISCOVERY ➤ Within the cluster: ClusterIP Service ➤ e.g.

    Kafka broker to Kafka broker, Kafka Connect worker to Kafka broker ➤ External services to Kafka: ➤ Bootstrapping: Cloud DNS to LoadBalancer ➤ Direct to broker: NodePort* * In our specific case, ClusterIP due to VPC-native IP aliasing on GCP. Also possible: dedicated LoadBalancers.
  20. SERVICE DISCOVERY ➤ Within the cluster: ClusterIP Service ➤ e.g.

    Kafka broker to Kafka broker, Kafka Connect worker to Kafka broker ➤ External services to Kafka: ➤ Bootstrapping: Cloud DNS to LoadBalancer ➤ Direct to broker: NodePort* ➤ Configuring your Kafka listeners * In our specific case, ClusterIP due to VPC-native IP aliasing on GCP. Also possible: dedicated LoadBalancers.
  21. SERVICE DISCOVERY ➤ Within the cluster: ClusterIP Service ➤ e.g.

    Kafka broker to Kafka broker, Kafka Connect worker to Kafka broker ➤ External services to Kafka: ➤ Bootstrapping: Cloud DNS to LoadBalancer ➤ Direct to broker: NodePort* ➤ Configuring your Kafka listeners * In our specific case, ClusterIP due to VPC-native IP aliasing on GCP. Also possible: dedicated LoadBalancers.
  22. SERVICE DISCOVERY ➤ Within the cluster: ClusterIP Service ➤ e.g.

    Kafka broker to Kafka broker, Kafka Connect worker to Kafka broker ➤ External services to Kafka: ➤ Bootstrapping: Cloud DNS to LoadBalancer ➤ Direct to broker: NodePort* ➤ Configuring your Kafka listeners ➤ https://rmoff.net/2018/08/02/kafka-listeners-explained/ * In our specific case, ClusterIP due to VPC-native IP aliasing on GCP. Also possible: dedicated LoadBalancers.
  23. SOME NOTES ON MANAGEMENT ➤ Installation, deploy: ➤ Confluent Helm

    charts ➤ https://github.com/confluentinc/cp-helm-charts
  24. SOME NOTES ON MANAGEMENT ➤ Installation, deploy: ➤ Confluent Helm

    charts ➤ https://github.com/confluentinc/cp-helm-charts ➤ No Tiller, Helm templating only
  25. SOME NOTES ON MANAGEMENT ➤ Installation, deploy: ➤ Confluent Helm

    charts ➤ https://github.com/confluentinc/cp-helm-charts ➤ No Tiller, Helm templating only ➤ Confluent Docker images, with additions
  26. SOME NOTES ON MANAGEMENT ➤ Monitoring: ➤ Kafka exposes JMX

    metrics by default ➤ Prometheus JMX Exporter as Java agent (vs. Helm chart sidecar)
  27. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions
  28. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions ➤ Check your JVM DNS cache TTL (networkaddress.cache.ttl)
  29. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions ➤ Check your JVM DNS cache TTL (networkaddress.cache.ttl)
  30. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions ➤ Check your JVM DNS cache TTL (networkaddress.cache.ttl) ➤ Check the Apache Kafka JIRA
  31. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions ➤ Check your JVM DNS cache TTL (networkaddress.cache.ttl) ➤ Oh, and upgrade Kafka.
  32. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions ➤ Check your JVM DNS cache TTL (networkaddress.cache.ttl) ➤ Check JIRA/Upgrade Kafka ➤ Producers and consumers too!
  33. WHAT WE LEARNED ➤ Ephemeral resources ➤ Don’t assume static

    IPs; make sure Kafka clients can handle pod evictions ➤ Check your JVM DNS cache TTL (networkaddress.cache.ttl) ➤ Check JIRA/Upgrade Kafka ➤ Producers and consumers too! ➤ Examples: KAFKA-7755, KAFKA-7890 ➤ See also: cp-helm-charts issue #240
  34. WHAT WE LEARNED ➤ Different kinds of updates/rolling restarts ➤

    Changes to Kafka cluster: versions, broker properties
  35. WHAT WE LEARNED ➤ Different kinds of updates/rolling restarts ➤

    Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies
  36. WHAT WE LEARNED ➤ Different kinds of updates/rolling restarts ➤

    Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes
  37. CONTAINER PROBES ➤ Liveness Probe
 “Should I restart this container?”

    ➤ Readiness Probe
 “Should this container accept traffic?”
  38. CONTAINER PROBES ➤ Liveness Probe
 “Should I restart this container?”

    ➤ Endpoint: is this broker healthy? ➤ Don’t be too strict!
  39. WHAT WE HAD TO FIGURE OUT ➤ Different kinds of

    updates/rolling restarts ➤ Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes ➤ How health checks affect updates
  40. WHAT WE HAD TO FIGURE OUT ➤ Different kinds of

    updates/rolling restarts ➤ Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes ➤ How health checks affect updates
  41. WHAT WE HAD TO FIGURE OUT ➤ Different kinds of

    updates/rolling restarts ➤ Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes ➤ How health checks affect updates ➤ podDisruptionBudget
  42. WHAT WE HAD TO FIGURE OUT ➤ Different kinds of

    updates/rolling restarts ➤ Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes ➤ How health checks affect updates ➤ podDisruptionBudget, podManagementPolicy
  43. WHAT WE HAD TO FIGURE OUT ➤ Different kinds of

    updates/rolling restarts ➤ Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes ➤ How health checks affect updates ➤ podDisruptionBudget, podManagementPolicy ➤ Health check overrides ➤ What happens if you deploy a change that breaks the health checks?
  44. WHAT WE HAD TO FIGURE OUT ➤ Different kinds of

    updates/rolling restarts ➤ Changes to Kafka cluster: versions, broker properties ➤ Workload configuration: resources, security policies ➤ Upgrading Kubernetes nodes ➤ How health checks affect updates ➤ podDisruptionBudget, podManagementPolicy ➤ Health check overrides ➤ What happens if you deploy a change that breaks the health checks? ➤ See Kubernetes issue #62750
  45. MIGRATING PRODUCTION ARCHITECTURE ➤ Get your hands dirty! ➤ Simulate

    common maintenance tasks ➤ Benchmark for performance ➤ kafka-producer-perf-test, kafka-consumer-perf-test
  46. MIGRATING PRODUCTION ARCHITECTURE ➤ Get your hands dirty! ➤ Simulate

    common maintenance tasks ➤ Benchmark for performance ➤ kafka-producer-perf-test, kafka-consumer-perf-test ➤ Variables: disk type, CPU count, producer record size, producer batch size, Java opts…
  47. MIGRATING PRODUCTION ARCHITECTURE ➤ Get your hands dirty! ➤ Simulate

    common maintenance tasks ➤ Benchmark for performance ➤ kafka-producer-perf-test, kafka-consumer-perf-test ➤ Variables: disk type, CPU count, producer record size, producer batch size, Java opts… ➤ We were able to use Compute Engine persistent disks (shared storage) rather than local SSDs
  48. MIGRATING PRODUCTION ARCHITECTURE ➤ Get your hands dirty! ➤ Simulate

    common maintenance tasks ➤ Benchmark for performance ➤ kafka-producer-perf-test, kafka-consumer-perf-test ➤ Variables: disk type, CPU count, producer record size, producer batch size, Java opts… ➤ We were able to use Compute Engine persistent disks (shared storage) rather than local SSDs ➤ Simulate failure
  49. MIGRATING PRODUCTION ARCHITECTURE ➤ Get your hands dirty! ➤ Simulate

    common maintenance tasks ➤ Benchmark for performance ➤ kafka-producer-perf-test, kafka-consumer-perf-test ➤ Variables: disk type, CPU count, producer record size, producer batch size, Java opts… ➤ We were able to use Compute Engine persistent disks (shared storage) rather than local SSDs ➤ Simulate failure
  50. WHY IT WORKS FOR US ➤ Increased automation ➤ Simpler

    configuration ➤ Efficient resource usage ➤ Bin packing ➤ GKE autoscaling
  51. WHY IT WORKS FOR US ➤ Increased automation ➤ Simpler

    configuration ➤ Efficient resource usage ➤ Bin packing ➤ GKE autoscaling ➤ Improved developer workflows for streaming services ➤ e.g. adding new Kafka Streams applications, Kafka Connect workloads